Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added feedback option in menus #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions Feedback/FeedbackActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.example.avjindersinghsekhon.minimaltodo.Feedback;

import android.content.pm.PackageInfo;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.NavUtils;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.widget.TextView;

import com.example.avjindersinghsekhon.minimaltodo.About.AboutFragment;
import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication;
import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity;
import com.example.avjindersinghsekhon.minimaltodo.Main.MainFragment;
import com.example.avjindersinghsekhon.minimaltodo.R;

public class FeedbackActivity extends AppDefaultActivity {

private TextView mVersionTextView;
private String appVersion = "0.1";
private Toolbar toolbar;
private TextView contactMe;
String theme;
// private UUID mId;
private AnalyticsApplication app;

@Override
protected void onCreate(Bundle savedInstanceState) {


theme = getSharedPreferences(MainFragment.THEME_PREFERENCES, MODE_PRIVATE).getString(MainFragment.THEME_SAVED, MainFragment.LIGHTTHEME);
if (theme.equals(MainFragment.DARKTHEME)) {
Log.d("OskarSchindler", "One");
setTheme(R.style.CustomStyle_DarkTheme);
} else {
Log.d("OskarSchindler", "One");
setTheme(R.style.CustomStyle_LightTheme);
}

super.onCreate(savedInstanceState);
// mId = (UUID)i.getSerializableExtra(TodoNotificationService.TODOUUID);

final Drawable backArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
if (backArrow != null) {
backArrow.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
appVersion = info.versionName;
} catch (Exception e) {
e.printStackTrace();
}

toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(backArrow);
}
}

@Override
protected int contentViewLayoutRes() {
return R.layout.feedback_layout;
}

@NonNull
protected Fragment createInitialFragment() {
return FeedbackFragment.newInstance();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
if (NavUtils.getParentActivityName(this) != null) {
NavUtils.navigateUpFromSameTask(this);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
117 changes: 117 additions & 0 deletions Feedback/FeedbackFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.example.avjindersinghsekhon.minimaltodo.Feedback;

import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.avjindersinghsekhon.minimaltodo.About.AboutFragment;
import com.example.avjindersinghsekhon.minimaltodo.Analytics.AnalyticsApplication;
import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity;
import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultFragment;
import com.example.avjindersinghsekhon.minimaltodo.R;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import static android.app.Activity.RESULT_OK;

/**
* Created by Awamry on 12/14/2018.
*/

public class FeedbackFragment extends AppDefaultFragment {
private Button sendAttachment;
private AnalyticsApplication app;
ImageView imageView;
EditText feedbackText;
TextView noAttachments;
Button sendEmail;
Uri uri;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

app = (AnalyticsApplication) getActivity().getApplication();
app.send(this);
sendAttachment = (Button) view.findViewById(R.id.attach_photo);
sendEmail = (Button) view.findViewById(R.id.send_email);
imageView = (ImageView) view.findViewById(R.id.imageView1);
feedbackText = (EditText) view.findViewById(R.id.feedback_text);
noAttachments = (TextView)view.findViewById(R.id.no_attachment_view);
sendAttachment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}
});

sendEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message = feedbackText.getText().toString();
String[] recipients = new String[]{"[email protected]"};
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,recipients);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Feedback Report");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,message);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri); //this line is added to your code
startActivity(emailIntent);
}
});

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if(requestCode==0&&resultCode==RESULT_OK&&data!=null&&data.getData()!=null){
noAttachments.setVisibility(View.INVISIBLE);
uri = data.getData();
try{
Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContext().getContentResolver(),uri);
imageView.setImageBitmap(bitmap);

} catch (IOException e) {
e.printStackTrace();
}
}
}

@LayoutRes
protected int layoutRes() {
return R.layout.fragment_feedback;
}

public static FeedbackFragment newInstance() {
return new FeedbackFragment();
}
}
86 changes: 86 additions & 0 deletions MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.example.avjindersinghsekhon.minimaltodo.Main;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.view.Menu;
import android.view.MenuItem;

import com.example.avjindersinghsekhon.minimaltodo.About.AboutActivity;
import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity;
import com.example.avjindersinghsekhon.minimaltodo.Feedback.FeedbackActivity;
import com.example.avjindersinghsekhon.minimaltodo.R;
import com.example.avjindersinghsekhon.minimaltodo.Settings.SettingsActivity;

public class MainActivity extends AppDefaultActivity {

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
}
}

@Override
protected int contentViewLayoutRes() {
return R.layout.activity_main;
}

@NonNull
@Override
protected Fragment createInitialFragment() {
return MainFragment.newInstance();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.aboutMeMenuItem:
Intent i = new Intent(this, AboutActivity.class);
startActivity(i);
return true;
// case R.id.switch_themes:
// if(mTheme == R.style.CustomStyle_DarkTheme){
// addThemeToSharedPreferences(LIGHTTHEME);
// }
// else{
// addThemeToSharedPreferences(DARKTHEME);
// }
//
//// if(mTheme == R.style.CustomStyle_DarkTheme){
//// mTheme = R.style.CustomStyle_LightTheme;
//// }
//// else{
//// mTheme = R.style.CustomStyle_DarkTheme;
//// }
// this.recreate();
// return true;
case R.id.preferences:
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;

case R.id.feedback:
Intent i2 = new Intent(this, FeedbackActivity.class);
startActivity(i2);
return true;

default:
return super.onOptionsItemSelected(item);
}
}

}


11 changes: 11 additions & 0 deletions feedback_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center|top"
android:layout_height="match_parent">

<include layout="@layout/base_toolbar"/>

<include layout="@layout/layout_fragment_container"/>
</LinearLayout>
87 changes: 87 additions & 0 deletions fragment_feedback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center|top"
android:layout_height="match_parent">

<ImageView
android:id="@+id/aboutImageView"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:layout_marginTop="50dp"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"/>

<TextView
android:text="@string/help_us"
android:gravity="center"
android:textSize="20sp"
android:id="@+id/help"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/aboutImageView"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/attach_photo"
android:layout_below="@id/help"
android:id="@+id/attach_photo"
android:layout_marginBottom="16dp"
android:layout_centerHorizontal="true"
/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Feedback"
android:layout_marginTop="16dp"
android:layout_above="@id/feedback_text"/>
<EditText
android:textSize="20sp"
android:layout_marginTop="16dp"
android:hint="Give us some feedback. "
android:layout_width="match_parent"
android:minLines="3"
android:gravity="top"
android:layout_height="wrap_content"
android:layout_below="@id/attach_photo"
android:id="@+id/feedback_text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/attachments"
android:layout_below="@id/feedback_text"
android:paddingTop="16dp"
android:id="@+id/attachments"
/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_below="@id/attachments"
android:id="@+id/imageView1"



/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/attachments"
android:text="No attachments yet."
android:id="@+id/no_attachment_view"
android:padding="32dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/send_feedback"
android:id="@+id/send_email"/>

</RelativeLayout>
Loading