Created
July 27, 2016 06:50
-
-
Save sagarpreet-chadha/8e82e44921fc6368536eb939876dc7b6 to your computer and use it in GitHub Desktop.
reminder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.app.Activity; | |
import android.app.DialogFragment; | |
import android.content.ContentValues; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.Intent; | |
import android.content.pm.PackageManager; | |
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteException; | |
import android.graphics.Bitmap; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.os.Environment; | |
import android.provider.MediaStore; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.design.widget.Snackbar; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.Toolbar; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.ImageView; | |
import android.widget.Toast; | |
import com.squareup.picasso.Picasso; | |
import java.io.ByteArrayOutputStream; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
public class AddListview_activity extends AppCompatActivity { | |
//private static final int RESULT_LOAD_IMAGE = 1; | |
private static final int REQUEST_CAMERA = 1; | |
private static final int SELECT_FILE = 2 ; | |
ImageView ivImage ; | |
String userChoosenTask; | |
Button add , alarm ; | |
EditText mtitle , mdesc ; | |
String title , desc ; | |
byte[] image=null ; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_add_listview_activity); | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
// FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); | |
// fab.setOnClickListener(new View.OnClickListener() { | |
// @Override | |
// public void onClick(View view) { | |
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) | |
// .setAction("Action", null).show(); | |
// } | |
// }); | |
mtitle = (EditText) findViewById(R.id.editText); | |
mdesc = (EditText) findViewById(R.id.editText2); | |
add = (Button) findViewById(R.id.add); | |
add.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
title = mtitle.getText().toString(); | |
desc = mdesc.getText().toString(); | |
if (image == null) { | |
Toast.makeText(AddListview_activity.this, "Add picture ", Toast.LENGTH_LONG); | |
} | |
//DbBitmapUtility u=new DbBitmapUtility() ; | |
Intent i = new Intent(); | |
i.putExtra("image", image); | |
i.putExtra("title", title); | |
i.putExtra("desc", desc); | |
// DatabaseHelper helper = new DatabaseHelper(AddListview_activity.this); | |
// SQLiteDatabase db = helper.getWritableDatabase(); | |
// | |
// ContentValues cv = new ContentValues(); | |
// cv.put(DatabaseHelper.KEY_TITLE, title ); | |
// cv.put(DatabaseHelper.KEY_DESC , desc ); | |
// //cv.put(CNOpenHelper.BATCH_INSTRUCTOR_NAME, b.getInstructorName()); | |
// cv.put(DatabaseHelper.KEY_IMAGE , image ); | |
// | |
// db.insert(DatabaseHelper.DB_TABLE, null, cv); | |
setResult(2, i); | |
finish(); | |
} | |
}); | |
Button load = (Button) findViewById(R.id.buttonLoadPicture); | |
load.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
// Intent i = new Intent( | |
// Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); | |
// | |
// startActivityForResult(i, RESULT_LOAD_IMAGE); | |
selectImage(); | |
} | |
}); | |
ivImage = (ImageView) findViewById(R.id.ivImage); | |
alarm = (Button) findViewById(R.id.alarm); | |
alarm.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
AlertDialog.Builder builder = new AlertDialog.Builder(AddListview_activity.this); | |
builder.setTitle("Add Date and Time!"); | |
View view = LayoutInflater.from(AddListview_activity.this).inflate(R.layout.date_and_time_add, null); | |
builder.setView(view); | |
Button date, time; | |
date = (Button) view.findViewById(R.id.date); | |
time = (Button) view.findViewById(R.id.time); | |
date.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
showDatePickerDialog(v); | |
} | |
}); | |
time.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
showTimePickerDialog(v); | |
} | |
} | |
); | |
builder.setPositiveButton("Done", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
} | |
}); | |
builder.show() ; | |
} | |
}); | |
} | |
public void showDatePickerDialog(View v) { | |
DialogFragment newFragment = new DatePickerFragment(); | |
newFragment.show(getFragmentManager(), "datePicker"); | |
} | |
public void showTimePickerDialog(View v) { | |
DialogFragment newFragment = new TimePickerFragment(); | |
//newFragment.show(getSupportFragmentManager(), "timePicker"); | |
newFragment.show(getFragmentManager() , "timePicker"); | |
} | |
// public void addEntry( String name, byte[] image) throws SQLiteException { | |
// SQLiteDatabase database = this.getWritableDatabase(); | |
// ContentValues cv = new ContentValues(); | |
// cv.put(KEY_TITLE, name); | |
// cv.put(KEY_IMAGE, image); | |
// database.insert( DB_TABLE, null, cv ); | |
// } | |
private void selectImage() { | |
final CharSequence[] items = {"Take Photo", "Choose from Library", | |
"Cancel"}; | |
AlertDialog.Builder builder = new AlertDialog.Builder(AddListview_activity.this); | |
builder.setTitle("Add Photo!"); | |
builder.setItems(items, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int item) { | |
boolean result = Utility.checkPermission(AddListview_activity.this); | |
if (items[item].equals("Take Photo")) { | |
userChoosenTask = "Take Photo"; | |
if (result) | |
cameraIntent(); | |
} else if (items[item].equals("Choose from Library")) { | |
userChoosenTask = "Choose from Library"; | |
if (result) | |
galleryIntent(); | |
} else if (items[item].equals("Cancel")) { | |
dialog.dismiss(); | |
} | |
} | |
}); | |
builder.show(); | |
} | |
private void cameraIntent() { | |
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); | |
startActivityForResult(intent, REQUEST_CAMERA); | |
} | |
private void galleryIntent() | |
{ | |
Intent intent = new Intent(); | |
intent.setType("image/*"); | |
intent.setAction(Intent.ACTION_GET_CONTENT);// | |
startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE); | |
} | |
@Override | |
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | |
switch (requestCode) { | |
case Utility.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE: | |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
if(userChoosenTask.equals("Take Photo")) | |
cameraIntent(); | |
else if(userChoosenTask.equals("Choose from Library")) | |
galleryIntent(); | |
} else { | |
//code for deny | |
} | |
break; | |
} | |
} | |
@Override | |
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |
super.onActivityResult(requestCode, resultCode, data); | |
if (resultCode == Activity.RESULT_OK) { | |
if (requestCode == SELECT_FILE) | |
onSelectFromGalleryResult(data); | |
else if (requestCode == REQUEST_CAMERA) | |
onCaptureImageResult(data); | |
} | |
} | |
@SuppressWarnings("deprecation") | |
private void onSelectFromGalleryResult(Intent data) { | |
Bitmap bm=null; | |
if (data != null) { | |
try { | |
bm = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), data.getData()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
image = DbBitmapUtility.getBytes(bm) ; | |
ivImage.setImageBitmap(bm); | |
} | |
private void onCaptureImageResult(Intent data) { | |
Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); | |
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); | |
thumbnail.compress(Bitmap.CompressFormat.JPEG, 90, bytes); | |
File destination = new File(Environment.getExternalStorageDirectory(), | |
System.currentTimeMillis() + ".jpg"); | |
FileOutputStream fo; | |
try { | |
destination.createNewFile(); | |
fo = new FileOutputStream(destination); | |
fo.write(bytes.toByteArray()); | |
fo.close(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
image = DbBitmapUtility.getBytes(thumbnail) ; | |
ivImage.setImageBitmap(thumbnail); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
/** | |
* Created by sagarpreet chadha on 26-07-2016. | |
*/ | |
import android.app.Fragment; | |
import android.os.Bundle; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.EditText; | |
/** | |
* A fragment representing the back of the card. | |
*/ | |
public class CardBackFragment extends Fragment { | |
View v ; | |
backtListener mListener ; | |
public interface backtListener | |
{ | |
void getDesc(String mtitle) ; | |
} | |
public void setBackFragmentListener(backtListener listener) { | |
mListener = listener; | |
} | |
public CardBackFragment() { | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
v=inflater.inflate(R.layout.fragment_card_back, container, false); | |
// EditText editText=(EditText)v.findViewById(R.id.editText4) ; | |
// String temp=editText.getText().toString() ; | |
// mListener.getDesc(temp); | |
return v ; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Context; | |
import android.net.Uri; | |
import android.os.Bundle; | |
import android.support.v4.app.Fragment; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
public class CardFrontFragment extends android.app.Fragment { | |
frontListener mListener ; | |
View v ; | |
public interface frontListener | |
{ | |
void getTitle(String title) ; | |
} | |
public void setFragmentListener(frontListener listener) { | |
mListener = listener; | |
} | |
public CardFrontFragment() { | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
v= inflater.inflate(R.layout.fragment_card_front, container, false); | |
// EditText title=(EditText)v.findViewById(R.id.editText3) ; | |
// String mt=title.getText().toString() ; | |
// mListener.getTitle(mt); | |
return v ; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Context; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
/** | |
* Created by sagarpreet chadha on 21-07-2016. | |
*/ | |
public class DatabaseHelper extends SQLiteOpenHelper { | |
// // Database Version | |
// private static final int DATABASE_VERSION = 1; | |
// | |
// // Database Name | |
// private static final String DATABASE_NAME = "database_name"; | |
// | |
// // Table Names | |
// static final String DB_TABLE = "table_image"; | |
// | |
// // column names | |
// static final String KEY_TITLE = "image_title"; | |
// static final String KEY_IMAGE = "image_data"; | |
// static final String KEY_DESC = "image_desc"; | |
// | |
// // Table create statement | |
// private static final String CREATE_TABLE_IMAGE = "CREATE TABLE " + DB_TABLE + "("+ | |
// KEY_TITLE + " TEXT," + | |
// KEY_IMAGE + " BLOB , " + | |
// KEY_DESC + "TEXT);"; | |
// | |
// public DatabaseHelper(Context context) { | |
// super(context, DATABASE_NAME, null, DATABASE_VERSION); | |
// } | |
// | |
// @Override | |
// public void onCreate(SQLiteDatabase db) { | |
// | |
// // creating table | |
// db.execSQL(CREATE_TABLE_IMAGE); | |
// } | |
// | |
// @Override | |
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |
// // on upgrade drop older tables | |
// db.execSQL("DROP TABLE IF EXISTS " + DB_TABLE); | |
// | |
// // create new table | |
// onCreate(db); | |
// } | |
public static final String DB_TABLE = "movies"; | |
public static final String KEY_TITLE = "image_title"; | |
public static final String KEY_IMAGE = "image_data"; | |
public static final String KEY_DESC = "image_desc"; | |
public DatabaseHelper(Context context) { | |
super(context, "CN", null, 1); | |
} | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
db.execSQL("create table " + DB_TABLE + " ( " + KEY_TITLE + " TEXT ," + | |
KEY_DESC + " TEXT, " + KEY_IMAGE + " BLOB);"); | |
// db.execSQL("create table students ( _ID INTEGER PRIMARY KEY ," + | |
// " batch_id INTEGER, name TEXT, college TEXT);"); | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.app.DatePickerDialog; | |
import android.app.Dialog; | |
import android.app.DialogFragment; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
import android.os.Bundle; | |
import android.widget.Button; | |
import android.widget.DatePicker; | |
import java.util.Calendar; | |
/** | |
* Created by sagarpreet chadha on 24-07-2016. | |
*/ | |
public class DatePickerFragment extends DialogFragment | |
implements DatePickerDialog.OnDateSetListener { | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
// Use the current date as the default date in the picker | |
final Calendar c = Calendar.getInstance(); | |
int year = c.get(Calendar.YEAR); | |
int month = c.get(Calendar.MONTH); | |
int day = c.get(Calendar.DAY_OF_MONTH); | |
// Create a new instance of DatePickerDialog and return it | |
DatePickerDialog db= new DatePickerDialog(getActivity(), this, year, month, day); | |
return db ; | |
} | |
public void onDateSet(DatePicker view, int year, int month, int day) { | |
// Do something with the date chosen by the user | |
// SharedPreferences.Editor sp = getSharedPreferences("blah", MODE_PRIVATE).edit(); | |
// sp.putString("gcm", token); | |
// sp.commit(); | |
// Button date=(Button) view.findViewById(R.id.date); | |
// date.setBackgroundColor(getResources().getColor(R.color.green)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import java.io.ByteArrayOutputStream; | |
/** | |
* Created by sagarpreet chadha on 21-07-2016. | |
*/ | |
public class DbBitmapUtility { | |
// convert from bitmap to byte array | |
public static byte[] getBytes(Bitmap bitmap) { | |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); | |
return stream.toByteArray(); | |
} | |
// convert from byte array to bitmap | |
public static Bitmap getImage(byte[] image) { | |
if(image==null){ | |
return null ; | |
} | |
return BitmapFactory.decodeByteArray(image, 0, image.length); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
/** | |
* Created by sagarpreet chadha on 19-07-2016. | |
*/ | |
public class faq { | |
String title ; | |
String desc ; | |
public faq(String title, String desc) { | |
this.title = title; | |
this.desc = desc; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public String getDesc() { | |
return desc; | |
} | |
public void setDesc(String desc) { | |
this.desc = desc; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Context; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.BaseExpandableListAdapter; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
/** | |
* Created by sagarpreet chadha on 19-07-2016. | |
*/ | |
public class FAQAdapter extends BaseExpandableListAdapter { | |
ArrayList<faq> data ; | |
LayoutInflater inflater; | |
public FAQAdapter(Context context, ArrayList<faq> dta){ | |
data=dta ; | |
inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
} | |
@Override | |
public int getGroupCount() { | |
return data.size() ; | |
} | |
@Override | |
public int getChildrenCount(int groupPosition) { | |
return 1; | |
} | |
@Override | |
public faq getGroup(int groupPosition) { | |
return data.get(groupPosition); | |
} | |
@Override | |
public String getChild(int groupPosition, int childPosition) { | |
return getGroup(groupPosition).getDesc() ; | |
} | |
@Override | |
public long getGroupId(int groupPosition) { | |
return groupPosition; | |
} | |
@Override | |
public long getChildId(int groupPosition, int childPosition) { | |
return groupPosition; | |
} | |
@Override | |
public boolean hasStableIds() { | |
return false; | |
} | |
@Override | |
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { | |
View output = convertView; | |
if(output==null){ | |
output = inflater.inflate(R.layout.row_layout_faq , parent,false); | |
} | |
String title=data.get(groupPosition).getTitle() ; | |
TextView textView = (TextView)output.findViewById(R.id.textView); | |
textView.setText(title); | |
return output; | |
} | |
@Override | |
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { | |
View output = convertView; | |
if(output==null){ | |
output = inflater.inflate(R.layout.row_layout_faq_child1 ,parent,false); | |
} | |
TextView textView = (TextView)output.findViewById(R.id.textView2); | |
String desc=data.get(groupPosition).getDesc() ; | |
textView.setText(desc); | |
return output; | |
} | |
@Override | |
public boolean isChildSelectable(int groupPosition, int childPosition) { | |
return false ; | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class FlipCard_activity extends AppCompatActivity implements CardFrontFragment.frontListener , CardBackFragment.backtListener { | |
String title , desc ; | |
boolean mShowingBack=false ; | |
CardBackFragment gf=new CardBackFragment(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
final CardFrontFragment bf = new CardFrontFragment(); | |
bf.setFragmentListener(this); | |
setContentView(R.layout.content_flip_card_activity); | |
if (savedInstanceState == null) { | |
getFragmentManager() | |
.beginTransaction() | |
.add(R.id.container, bf) | |
.commit(); | |
} | |
Button button=(Button)findViewById(R.id.button) ; | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
flipCard(); | |
} | |
}); | |
gf.setBackFragmentListener(this); | |
Button add=(Button)findViewById(R.id.addfaq) ; | |
add.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
EditText mtitle=(EditText)bf.v.findViewById(R.id.editText3) ; | |
EditText mdesc=(EditText)gf.v.findViewById(R.id.editText4) ; | |
title=mtitle.getText().toString() ; | |
desc=mdesc.getText().toString() ; | |
if(title!="" && desc!="") | |
{ | |
Intent f=new Intent() ; | |
f.putExtra("title" , title) ; | |
f.putExtra("desc" , desc) ; | |
setResult(3 , f); | |
finish(); | |
} | |
else | |
{ | |
Toast.makeText(FlipCard_activity.this , "Add Title as well as Descrition " , Toast.LENGTH_LONG).show(); | |
} | |
} | |
}); | |
Button cncel=(Button)findViewById(R.id.cancel) ; | |
cncel.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
finish(); | |
} | |
}); | |
} | |
@Override | |
public void getTitle(String mtitle) { | |
title=mtitle ; | |
} | |
// | |
// | |
// public static class CardFrontFragment extends Fragment { | |
// | |
// public CardFrontFragment() { | |
// | |
// } | |
// | |
// @Override | |
// public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
// Bundle savedInstanceState) { | |
// View v= inflater.inflate(R.layout.fragment_card_front, container, false); | |
//// EditText title=(EditText)v.findViewById(R.id.editText3) ; | |
// // mt=title.getText().toString() ; | |
// | |
// return v ; | |
// } | |
// } | |
// /** | |
// * A fragment representing the back of the card. | |
// */ | |
// public static class CardBackFragment extends Fragment { | |
// @Override | |
// public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
// Bundle savedInstanceState) { | |
// return inflater.inflate(R.layout.fragment_card_back, container, false); | |
// } | |
// } | |
private void flipCard() { | |
if (mShowingBack) { | |
getFragmentManager().popBackStack(); | |
mShowingBack=false ; | |
return; | |
} | |
// Flip to the back. | |
mShowingBack = true; | |
// Create and commit a new fragment transaction that adds the fragment for | |
// the back of the card, uses custom animations, and is part of the fragment | |
// manager's back stack. | |
getFragmentManager() | |
.beginTransaction() | |
// Replace the default fragment animations with animator resources | |
// representing rotations when switching to the back of the card, as | |
// well as animator resources representing rotations when flipping | |
// back to the front (e.g. when the system Back button is pressed). | |
.setCustomAnimations( | |
R.animator.card_flip_right_in , | |
R.animator.card_flip_right_out, | |
R.animator.card_flip_left_in, | |
R.animator.card_flip_left_out) | |
// Replace any fragments currently in the container view with a | |
// fragment representing the next page (indicated by the | |
// just-incremented currentPage variable). | |
.replace(R.id.container, gf) | |
// Add this transaction to the back stack, allowing users to press | |
// Back to get to the front of the card. | |
.addToBackStack(null) | |
// Commit the transaction. | |
.commit(); | |
} | |
@Override | |
public void getDesc(String mtitle) { | |
desc=mtitle ; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.ArrayAdapter; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import com.squareup.picasso.Picasso; | |
import java.util.ArrayList; | |
/** | |
* Created by sagarpreet chadha on 19-07-2016. | |
*/ | |
public class ListView_Adapter extends ArrayAdapter<Reminder_listview_data> { | |
ArrayList<Reminder_listview_data> mData; | |
Context context; | |
public ListView_Adapter(Context context, ArrayList<Reminder_listview_data> objects) { | |
super(context, 0, objects); | |
mData = objects; | |
this.context = context; | |
} | |
// @Override | |
// public int getViewTypeCount() { | |
// return 1; | |
// } | |
// @Override | |
// public int getItemViewType(int position) { | |
// return | |
// } | |
@Override | |
public int getCount() { | |
// HashMap<String, ArrayList<Task>> map = new HashMap<>(); | |
// for (String key : map.keySet()) { | |
// | |
// } | |
return (mData.size()) ; | |
} | |
// private static class BatchHolder { | |
// TextView batchNameTextView; | |
// TextView instructorNameTextView; | |
// TextView numStudentsTextView; | |
// ImageView imageView; | |
// | |
// public BatchHolder(TextView batchNameTextView, TextView instructorNameTextView, TextView numStudentsTextView, ImageView imageView) { | |
// this.batchNameTextView = batchNameTextView; | |
// this.instructorNameTextView = instructorNameTextView; | |
// this.numStudentsTextView = numStudentsTextView; | |
// this.imageView = imageView; | |
// } | |
// } | |
@Override | |
public View getView(int position, View convertView, ViewGroup parent) { | |
View v = LayoutInflater.from(context).inflate(R.layout.listview_layout , | |
parent, false); | |
ImageView imageView=(ImageView)v.findViewById(R.id.imageView) ; | |
TextView title=(TextView)v.findViewById(R.id.mtitle) ; | |
TextView desc=(TextView)v.findViewById(R.id.mdescription) ; | |
Reminder_listview_data temp=mData.get(position) ; | |
String mtitle , mdesc ; | |
Bitmap bm=temp.getBm() ; | |
mtitle=temp.getTitle() ; | |
mdesc=temp.getDesc() ; | |
if(bm!=null) { | |
imageView.setImageBitmap(bm); | |
} | |
title.setText(mtitle) ; | |
desc.setText(mdesc) ; | |
return v; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.ContentValues; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.database.Cursor; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.graphics.Bitmap; | |
import android.support.design.widget.TabLayout; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.design.widget.Snackbar; | |
import android.support.v7.app.AppCompatActivity; | |
import android.support.v7.widget.LinearLayoutManager; | |
import android.support.v7.widget.RecyclerView; | |
import android.support.v7.widget.SearchView; | |
import android.support.v7.widget.Toolbar; | |
import android.support.v4.app.Fragment; | |
import android.support.v4.app.FragmentManager; | |
import android.support.v4.app.FragmentPagerAdapter; | |
import android.support.v4.view.ViewPager; | |
import android.os.Bundle; | |
import android.support.v7.widget.helper.ItemTouchHelper; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.view.animation.Animation; | |
import android.view.animation.AnimationUtils; | |
import android.widget.ExpandableListAdapter; | |
import android.widget.ExpandableListView; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | |
static ExpandableListView expandableListView ; | |
static FAQAdapter adapter ; | |
static ArrayList<faq> mdata=new ArrayList<>() ; | |
static ArrayList<Reminder_listview_data> reminderdata=new ArrayList<>() ; | |
static RecyclerView recyclerView ; | |
static RCVAdapter radapter ; | |
private Boolean isFabOpen = false; | |
private FloatingActionButton fab,fab1,fab2; | |
private Animation fab_open,fab_close,rotate_forward,rotate_backward; | |
/** | |
* The {@link android.support.v4.view.PagerAdapter} that will provide | |
* fragments for each of the sections. We use a | |
* {@link FragmentPagerAdapter} derivative, which will keep every | |
* loaded fragment in memory. If this becomes too memory intensive, it | |
* may be best to switch to a | |
* {@link android.support.v4.app.FragmentStatePagerAdapter}. | |
*/ | |
SearchView searchView ; | |
private SectionsPagerAdapter mSectionsPagerAdapter; | |
/** | |
* The {@link ViewPager} that will host the section contents. | |
*/ | |
private ViewPager mViewPager; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
fab = (FloatingActionButton)findViewById(R.id.fab); | |
fab1 = (FloatingActionButton)findViewById(R.id.fab1); | |
fab2 = (FloatingActionButton)findViewById(R.id.fab2); | |
fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open); | |
fab_close = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fab_close); | |
rotate_forward = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_forward); | |
rotate_backward = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate_backward); | |
fab.setOnClickListener(this); | |
fab1.setOnClickListener(this); | |
fab2.setOnClickListener(this); | |
// listView=(ListView)findViewById(R.id.listView) ; | |
// adapter = new ListView_Adapter(this , reminderdata); | |
// listView.setAdapter(adapter); | |
DatabaseHelper helper = new DatabaseHelper(this); | |
SQLiteDatabase db = helper.getReadableDatabase(); | |
Cursor c = db.query(DatabaseHelper.DB_TABLE , null , null, null, null, null, null); | |
reminderdata.clear(); | |
Reminder_listview_data t=new Reminder_listview_data("REMINDER 1" , "Complete this app " , null) ; | |
reminderdata.add(t); | |
while (c.moveToNext()) { | |
String title = c.getString(c.getColumnIndex(DatabaseHelper.KEY_TITLE)); | |
String desc = c.getString(c.getColumnIndex(DatabaseHelper.KEY_DESC)); | |
byte[] imagebyte=c.getBlob(c.getColumnIndex(DatabaseHelper.KEY_IMAGE)) ; | |
// String id = String.valueOf(c.getInt(c.getColumnIndex(CNOpenHelper.BATCH_TABLE_ID))); | |
// int vote = c.getInt(c.getColumnIndex(CNOpenHelper.BATCH_VOTE_COUNT)); | |
Bitmap bitmap=DbBitmapUtility.getImage(imagebyte) ; | |
//Batch b = new Batch(name,instuctorName,strength,id); | |
//data.add(b); | |
Reminder_listview_data x=new Reminder_listview_data(title , desc , bitmap) ; | |
reminderdata.add(x); | |
} | |
mdata.add(new faq("Click On Button" , "To add reminder or a quick note , " + | |
"BLUE for Quick Note and PINK for Reminder :)")) ; | |
// mdata.add(new faq("Title2" , "Desc2")) ; | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
// Create the adapter that will return a fragment for each of the three | |
// primary sections of the activity. | |
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); | |
// Set up the ViewPager with the sections adapter. | |
mViewPager = (ViewPager) findViewById(R.id.container); | |
mViewPager.setAdapter(mSectionsPagerAdapter); | |
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); | |
tabLayout.setupWithViewPager(mViewPager); | |
tabLayout.getTabAt(0).setIcon(R.drawable.reminders_white_18dp); | |
tabLayout.getTabAt(1).setIcon(R.drawable.faq); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if(requestCode==1) | |
{ | |
if(resultCode==2) | |
{ | |
// DatabaseHelper helper = new DatabaseHelper(MainActivity.this); | |
// SQLiteDatabase db = helper.getReadableDatabase(); | |
// | |
// Cursor c = db.query(DatabaseHelper.DB_TABLE , null , null, null, null, null, null); | |
// reminderdata.clear(); | |
// while (c.moveToNext()) { | |
// String title = c.getString(c.getColumnIndex(DatabaseHelper.KEY_TITLE)); | |
// String desc = c.getString(c.getColumnIndex(DatabaseHelper.KEY_DESC)); | |
// byte[] imagebyte=c.getBlob(c.getColumnIndex(DatabaseHelper.KEY_IMAGE)) ; | |
// // String id = String.valueOf(c.getInt(c.getColumnIndex(CNOpenHelper.BATCH_TABLE_ID))); | |
// // int vote = c.getInt(c.getColumnIndex(CNOpenHelper.BATCH_VOTE_COUNT)); | |
// Bitmap bitmap=DbBitmapUtility.getImage(imagebyte) ; | |
// | |
// //Batch b = new Batch(name,instuctorName,strength,id); | |
// //data.add(b); | |
// Reminder_listview_data x=new Reminder_listview_data(title , desc , bitmap) ; | |
// | |
// reminderdata.add(x); | |
// } | |
DatabaseHelper helper = new DatabaseHelper(MainActivity.this); | |
SQLiteDatabase db = helper.getWritableDatabase(); | |
ContentValues cv = new ContentValues(); | |
cv.put(DatabaseHelper.KEY_TITLE, data.getStringExtra("title") ); | |
cv.put(DatabaseHelper.KEY_DESC , data.getStringExtra("desc") ); | |
//cv.put(CNOpenHelper.BATCH_INSTRUCTOR_NAME, b.getInstructorName()); | |
cv.put(DatabaseHelper.KEY_IMAGE , data.getByteArrayExtra("image") ); | |
db.insert(DatabaseHelper.DB_TABLE, null, cv); | |
Bitmap bitmap=DbBitmapUtility.getImage(data.getByteArrayExtra("image")) ; | |
reminderdata.add(new Reminder_listview_data(data.getStringExtra("title") , data.getStringExtra("desc") , bitmap)); | |
radapter.notifyDataSetChanged(); | |
} | |
} | |
else if(requestCode==2) | |
{ | |
if(resultCode==3) | |
{ | |
String mt=data.getStringExtra("title") ; | |
String md=data.getStringExtra("desc") ; | |
mdata.add(new faq(mt , md)); | |
adapter.notifyDataSetChanged() ; | |
} | |
} | |
} | |
@Override | |
public void onClick(View v) { | |
int id = v.getId(); | |
switch (id){ | |
case R.id.fab: | |
animateFAB(); | |
break; | |
case R.id.fab1: | |
Intent intent=new Intent() ; | |
intent.setClass(MainActivity.this , FlipCard_activity.class) ; | |
startActivityForResult(intent , 2 ); | |
break; | |
case R.id.fab2: | |
Intent i=new Intent() ; | |
i.setClass(MainActivity.this , AddListview_activity.class); | |
startActivityForResult(i , 1); | |
break; | |
} | |
} | |
public void animateFAB(){ | |
if(isFabOpen){ | |
fab.startAnimation(rotate_backward); | |
fab1.startAnimation(fab_close); | |
fab2.startAnimation(fab_close); | |
fab1.setClickable(false); | |
fab2.setClickable(false); | |
isFabOpen = false; | |
Log.d("Raj", "close"); | |
} else { | |
fab.startAnimation(rotate_forward); | |
fab1.startAnimation(fab_open); | |
fab2.startAnimation(fab_open); | |
fab1.setClickable(true); | |
fab2.setClickable(true); | |
isFabOpen = true; | |
Log.d("Raj","open"); | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// // Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
final MenuItem myActionMenuItem = menu.findItem( R.id.action_search); | |
searchView = (SearchView) myActionMenuItem.getActionView(); | |
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
@Override | |
public boolean onQueryTextSubmit(String query) { | |
// Toast.makeText(MainActivity.this , query , Toast.LENGTH_LONG) ; | |
if( ! searchView.isIconified()) { | |
searchView.setIconified(true); | |
} | |
myActionMenuItem.collapseActionView(); | |
return false; | |
} | |
@Override | |
public boolean onQueryTextChange(String s) { | |
// UserFeedback.show( "SearchOnQueryTextChanged: " + s); | |
return false; | |
} | |
}); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
// Handle action bar item clicks here. The action bar will | |
// automatically handle clicks on the Home/Up button, so long | |
// as you specify a parent activity in AndroidManifest.xml. | |
int id = item.getItemId(); | |
//noinspection SimplifiableIfStatement | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
/** | |
* A placeholder fragment containing a simple view. | |
*/ | |
public static class PlaceholderFragment extends Fragment { | |
/** | |
* The fragment argument representing the section number for this | |
* fragment. | |
*/ | |
private static final String ARG_SECTION_NUMBER = "section_number"; | |
public PlaceholderFragment() { | |
} | |
/** | |
* Returns a new instance of this fragment for the given section | |
* number. | |
*/ | |
public static PlaceholderFragment newInstance(int sectionNumber) { | |
PlaceholderFragment fragment = new PlaceholderFragment(); | |
Bundle args = new Bundle(); | |
args.putInt(ARG_SECTION_NUMBER, sectionNumber); | |
fragment.setArguments(args); | |
return fragment; | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
View rootView=null ; | |
if( getArguments().getInt(ARG_SECTION_NUMBER)==1) { | |
rootView = inflater.inflate(R.layout.reminder_fragment, container, false); | |
LinearLayoutManager lm=new LinearLayoutManager(getContext()) ; | |
lm.setOrientation(LinearLayoutManager.VERTICAL); | |
recyclerView=(RecyclerView)rootView.findViewById(R.id.listview) ; | |
recyclerView.setLayoutManager(lm); | |
radapter=new RCVAdapter(getContext() , reminderdata ) ; | |
recyclerView.setAdapter(radapter); | |
ItemTouchHelper.SimpleCallback callback=new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN |ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT , 0){ | |
@Override | |
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { | |
int first=viewHolder.getAdapterPosition() ; | |
int second=target.getAdapterPosition() ; | |
Reminder_listview_data b1=reminderdata.get(first) ; | |
Reminder_listview_data b2=reminderdata.get(second) ; | |
reminderdata.set(first , b2) ; | |
reminderdata.set(second , b1) ; | |
radapter.notifyItemMoved(first , second); | |
return true; | |
} | |
@Override | |
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { | |
// int position=viewHolder.getAdapterPosition() ; | |
// Reminder_listview_data temp=reminderdata.get(position) ; | |
// | |
// DatabaseHelper helper = new DatabaseHelper(getContext()); | |
// SQLiteDatabase db = helper.getWritableDatabase(); | |
// | |
// // db.delete(DatabaseHelper.DB_TABLE, DatabaseHelper.KEY_TITLE + "=" + temp.getTitle() + " and " + DatabaseHelper.KEY_DESC + "=" + temp.getDesc() , null); | |
// | |
// reminderdata.remove(position) ; | |
// radapter.notifyItemRemoved(position); | |
} | |
}; | |
ItemTouchHelper helper=new ItemTouchHelper(callback) ; | |
helper.attachToRecyclerView(recyclerView); | |
// onActivityResult(1 , 2 , null) ; | |
} | |
else if( getArguments().getInt(ARG_SECTION_NUMBER)==2) | |
{ | |
rootView = inflater.inflate(R.layout.faq_fragment, container, false); | |
expandableListView=(ExpandableListView)rootView.findViewById(R.id.expandableListView) ; | |
adapter=new FAQAdapter(getContext() , mdata) ; | |
expandableListView.setAdapter(adapter); | |
} | |
return rootView; | |
} | |
} | |
/** | |
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to | |
* one of the sections/tabs/pages. | |
*/ | |
public class SectionsPagerAdapter extends FragmentPagerAdapter { | |
public SectionsPagerAdapter(FragmentManager fm) { | |
super(fm); | |
} | |
@Override | |
public Fragment getItem(int position) { | |
// getItem is called to instantiate the fragment for the given page. | |
// Return a PlaceholderFragment (defined as a static inner class below). | |
return PlaceholderFragment.newInstance(position + 1); | |
} | |
@Override | |
public int getCount() { | |
// Show 3 total pages. | |
return 2; | |
} | |
@Override | |
public CharSequence getPageTitle(int position) { | |
switch (position) { | |
case 0: | |
return "REMINDERS"; | |
case 1: | |
return "QUICK NOTE"; | |
} | |
return null; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.content.Context; | |
import android.graphics.Bitmap; | |
import android.support.v7.widget.RecyclerView; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.Button; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.util.ArrayList; | |
/** | |
* Created by sagarpreet chadha on 24-07-2016. | |
*/ | |
public class RCVAdapter extends RecyclerView.Adapter<RCVAdapter.ourHolder> { | |
Context mcontext ; | |
ArrayList<Reminder_listview_data> mdata ; | |
listener mlistener ; | |
public class ourHolder extends RecyclerView.ViewHolder{ | |
TextView title ; | |
TextView desc ; | |
ImageView imageView; | |
public ourHolder(View v) { | |
super(v); | |
imageView=(ImageView)v.findViewById(R.id.imageView) ; | |
title=(TextView)v.findViewById(R.id.mtitle) ; | |
desc=(TextView)v.findViewById(R.id.mdescription) ; | |
} | |
} | |
public interface listener{ | |
// void BatchClick(Batch b) ; | |
} | |
public RCVAdapter(Context context , ArrayList<Reminder_listview_data> batches) { | |
mdata=batches ; | |
mcontext=context ; | |
// mlistener=l ; | |
} | |
@Override | |
public RCVAdapter.ourHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View v= LayoutInflater.from(mcontext).inflate(R.layout.listview_layout , parent , false) ; | |
return (new ourHolder(v)) ; | |
} | |
@Override | |
public void onBindViewHolder(RCVAdapter.ourHolder holder , final int position) { | |
final Reminder_listview_data b=mdata.get(position) ; | |
holder.title.setText(b.getTitle()); | |
holder.desc.setText(b.getDesc()+""); | |
Bitmap bm=b.getBm() ; | |
if(bm!=null) { | |
holder.imageView.setImageBitmap(bm); | |
} | |
// holder.b.setOnClickListener(new View.OnClickListener() { | |
// @Override | |
// public void onClick(View v) { | |
// mlistener.BatchClick(b) ; | |
// } | |
// }); | |
} | |
@Override | |
public int getItemCount() { | |
return mdata.size() ; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.graphics.Bitmap; | |
/** | |
* Created by sagarpreet chadha on 21-07-2016. | |
*/ | |
public class Reminder_listview_data { | |
String title ; | |
String desc ; | |
Bitmap bm ; | |
public Reminder_listview_data(String title, String desc, Bitmap bm) { | |
this.title = title; | |
this.desc = desc; | |
this.bm = bm; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public void setTitle(String title) { | |
this.title = title; | |
} | |
public String getDesc() { | |
return desc; | |
} | |
public void setDesc(String desc) { | |
this.desc = desc; | |
} | |
public Bitmap getBm() { | |
return bm; | |
} | |
public void setBm(Bitmap bm) { | |
this.bm = bm; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.app.Dialog; | |
import android.app.DialogFragment; | |
import android.app.TimePickerDialog; | |
import android.os.Bundle; | |
import android.text.format.DateFormat; | |
import android.widget.Button; | |
import android.widget.TimePicker; | |
import java.util.Calendar; | |
/** | |
* Created by sagarpreet chadha on 24-07-2016. | |
*/ | |
public class TimePickerFragment extends DialogFragment | |
implements TimePickerDialog.OnTimeSetListener { | |
@Override | |
public Dialog onCreateDialog(Bundle savedInstanceState) { | |
// Use the current time as the default values for the picker | |
final Calendar c = Calendar.getInstance(); | |
int hour = c.get(Calendar.HOUR_OF_DAY); | |
int minute = c.get(Calendar.MINUTE); | |
// Create a new instance of TimePickerDialog and return it | |
return new TimePickerDialog(getActivity(), this, hour, minute, | |
DateFormat.is24HourFormat(getActivity())); | |
} | |
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { | |
// Do something with the time chosen by the user | |
// Button time=(Button) view.findViewById(R.id.time); | |
// time.setBackgroundColor(getResources().getColor(R.color.green)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sagarpreet97.reminder; | |
import android.Manifest; | |
import android.annotation.TargetApi; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.DialogInterface; | |
import android.content.pm.PackageManager; | |
import android.os.Build; | |
import android.support.v4.app.ActivityCompat; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.AlertDialog; | |
/** | |
* Created by sagarpreet chadha on 19-07-2016. | |
*/ | |
public class Utility { | |
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 123; | |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
public static boolean checkPermission(final Context context) | |
{ | |
int currentAPIVersion = Build.VERSION.SDK_INT; | |
if(currentAPIVersion>=android.os.Build.VERSION_CODES.M) | |
{ | |
if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | |
if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, Manifest.permission.READ_EXTERNAL_STORAGE)) { | |
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context); | |
alertBuilder.setCancelable(true); | |
alertBuilder.setTitle("Permission necessary"); | |
alertBuilder.setMessage("External storage permission is necessary"); | |
alertBuilder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { | |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) | |
public void onClick(DialogInterface dialog, int which) { | |
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); | |
} | |
}); | |
AlertDialog alert = alertBuilder.create(); | |
alert.show(); | |
} else { | |
ActivityCompat.requestPermissions((Activity) context, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); | |
} | |
return false; | |
} else { | |
return true; | |
} | |
} else { | |
return true; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment