Android Open Source - Now_Manager Activity Settings






From Project

Back to project page Now_Manager.

License

The source code is released under:

Apache License

If you think the Android project Now_Manager listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.collinguarino.nowmanager.ui;
//w  w w .  j  a va2 s.  com
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.text.format.DateFormat;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

import com.collinguarino.nowmanager.R;
import com.collinguarino.nowmanager.TimeCardAdapter;
import com.collinguarino.nowmanager.provider.Contracts;
import com.collinguarino.nowmanager.provider.MainDatabaseHelper;

import java.io.File;
import java.util.Calendar;
import java.util.Date;

public class ActivitySettings extends PreferenceActivity  {

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

        addPreferencesFromResource(R.layout.activity_settings);

        setContentView(R.layout.fragment_settings_header); // uses the listview in fragment_settings_header as the preferenceresource

        ImageButton share = (ImageButton) findViewById(R.id.share);
        share.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                String shareBody = "Now Manager App: https://play.google.com/store/apps/details?id=com.collinguarino.nowmanager";
                sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
                startActivity(Intent.createChooser(sharingIntent, "Share To:"));
            }
        });

        ImageButton rate = (ImageButton) findViewById(R.id.rate);
        rate.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                try {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.collinguarino.nowmanager")));
                } catch (android.content.ActivityNotFoundException anfe) {
                    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.collinguarino.nowmanager")));
                }
            }
        });

        (findPreference("delete_all")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                showDeleteAllConfirmation();
                return true;
            }
        });

        (findPreference("share_all")).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                showShareIntentChooser();
                return true;
            }
        });
    }

    private void showShareIntentChooser() {
        String shareBody = "";

        // query the database for all rows
        MainDatabaseHelper mOpenHelper = new MainDatabaseHelper(this.getApplicationContext());
        final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
        Cursor c = db.rawQuery("select * from " + Contracts.TimeCards.TABLE_NAME +
                " WHERE " + Contracts.TimeCards.C_IS_IMAGE + " =0" +
                " AND " + Contracts.TimeCards.C_IS_VOICE + " =0", null);

        while(c.moveToNext()) {

            // setting name
            String eventName = c.getString(c.getColumnIndex(Contracts.TimeCards.C_EVENT_NAME_INPUT));
            if (eventName.length() == 0)
                eventName = "Untitled";
            shareBody += eventName + "\n";

            // setting date and time
            final Calendar datetimeCalendar = Calendar.getInstance();
            datetimeCalendar.setTimeInMillis(c.getLong(c.getColumnIndex(Contracts.TimeCards.C_TIMESTAMP)));
            final Date dateTime = datetimeCalendar.getTime();
            String timeText = "";
            if (!DateFormat.is24HourFormat(ActivitySettings.this)) {
                timeText = TimeCardAdapter.TIME_FORMAT_STANDARD.format(dateTime);
            } else if (DateFormat.is24HourFormat(ActivitySettings.this)) {
                timeText = TimeCardAdapter.TIME_FORMAT_MILITARY.format(dateTime);
            }
            shareBody += TimeCardAdapter.DATE_FORMAT.format(dateTime) + " " + timeText;

            // prepare for new line
            if (!c.isLast()) {
                shareBody += "\n\n";
            }

        }
        db.close();
        c.close();

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, "Share To:"));
    }

    private void showDeleteAllConfirmation() {
        AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
        builder1.setTitle("Delete All Activities?");
        builder1.setMessage("This action cannot be undone.");
        builder1.setCancelable(true);

        // delete
        builder1.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                MainDatabaseHelper mOpenHelper = new MainDatabaseHelper(getBaseContext());
                final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
                Cursor c = db.rawQuery("select * from " + Contracts.TimeCards.TABLE_NAME, null);

                while(c.moveToNext()) {
                    // if there's a filepath, delete the file there
                    if (c.getInt(c.getColumnIndex(Contracts.TimeCards.C_IS_IMAGE)) == 1 || c.getInt(c.getColumnIndex(Contracts.TimeCards.C_IS_VOICE)) == 1) {
                        File file = new File(c.getString(c.getColumnIndex(Contracts.TimeCards.C_FILE_PATH)));
                        file.delete();
                    }
                }
                db.close();
                c.close();

                getContentResolver().delete(Contracts.TimeCards.CONTENT_URI, null, null);

                Toast toast = Toast.makeText(getApplicationContext(), "All Activities Deleted", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.BOTTOM,0,280);
                toast.show();
            }
        });

        // don't proceed
        builder1.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

        AlertDialog alert = builder1.create();
        alert.show();
    }
}




Java Source Code List

com.collinguarino.nowmanager.AsyncGPSLog.java
com.collinguarino.nowmanager.EditTextBackEvent.java
com.collinguarino.nowmanager.EditTextMovement.java
com.collinguarino.nowmanager.SwipeDismissListViewTouchListener.java
com.collinguarino.nowmanager.TimeCardAdapter.java
com.collinguarino.nowmanager.TimeCardObject.java
com.collinguarino.nowmanager.floating.AddFloatingActionButton.java
com.collinguarino.nowmanager.floating.FloatingActionButton.java
com.collinguarino.nowmanager.floating.FloatingActionsMenu.java
com.collinguarino.nowmanager.provider.Contracts.java
com.collinguarino.nowmanager.provider.MainDatabaseHelper.java
com.collinguarino.nowmanager.provider.NowManagerProvider.java
com.collinguarino.nowmanager.ui.ActivityMain.java
com.collinguarino.nowmanager.ui.ActivitySettings.java
com.collinguarino.nowmanager.ui.Dialogs.java