Example usage for android.preference PreferenceManager setDefaultValues

List of usage examples for android.preference PreferenceManager setDefaultValues

Introduction

In this page you can find the example usage for android.preference PreferenceManager setDefaultValues.

Prototype

public static void setDefaultValues(Context context, @XmlRes int resId, boolean readAgain) 

Source Link

Document

Sets the default values from an XML preference file by reading the values defined by each Preference item's android:defaultValue attribute.

Usage

From source file:com.qasp.diego.arsp.MainActivity.java

@SuppressWarnings("unchecked")
@Override/*w ww. ja v a 2s . c  o m*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
        // Activity was brought to front and not created,
        // Thus finishing this will get us to the last viewed activity
        finish();
        return;
    }

    // Opcoes padrao para Preferencias.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    setContentView(R.layout.activity_main);

    // Salva dados se nao for mais visivel
    if (savedInstanceState != null) {
        Global.estacoes = (ArrayList<Estacao>) savedInstanceState.getSerializable(ESTADO_ESTACOES);
        Global.GPS = (Coordenada) savedInstanceState.getSerializable(ESTADO_GPS);
    } else
        InicializaEstacoesValidas(Global.estacoes);

    // Colorizao da barra de servios.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.parseColor("#202020"));
    }

    // PERMISSOES
    verifyStoragePermissions(this);
    if (PermissaodoGPS(this)) {
        // Se a permisso ja foi aprovada anterioremente.
        Intent intent = new Intent(this, LocalizacaoGPSService.class);
        startService(intent);
    }

    // Action bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // TABS.
    tablayout = (TabLayout) findViewById(R.id.tab_layout);
    tablayout.addTab(tablayout.newTab().setText("Lista Estaes"));
    tablayout.addTab(tablayout.newTab().setText("Indice Local"));
    tablayout.addTab(tablayout.newTab().setText("Feedback"));
    tablayout.setTabGravity(TabLayout.GRAVITY_FILL);

    // PAGER (Deslize) e Funcionamento das Tabs
    viewPager = (ViewPager) findViewById(R.id.pager);
    adapter = new PagerAdapter(getSupportFragmentManager(), tablayout.getTabCount());
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tablayout));
    tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            // Notificar eventuais mudanas ao mudar de aba.
            Global.tabSelecionado = tab.getPosition();
            viewPager.setCurrentItem(tab.getPosition());
            viewPager.getAdapter().notifyDataSetChanged();
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            // vazio de proposito
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            // Vazio de proposito
        }
    });
}

From source file:org.isoron.uhabits.MainActivity.java

private void onStartup() {
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    DialogHelper.incrementLaunchCount(this);
    DialogHelper.updateLastAppVersion(this);
    showTutorial();//from   ww w  . j  a va  2s .c om

    new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            ReminderHelper.createReminderAlarms(MainActivity.this);
            updateWidgets(MainActivity.this);
            return null;
        }
    }.execute();

}

From source file:com.hybris.mobile.Hybris.java

public void onCreate() {
    super.onCreate();

    // TODO - Delete this too heavy exception process not adapted for Android?
    //      ExceptionHandler.register(this);

    // Saving the application context
    setContext(this);

    // Load preference defaults
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Updating the webservices URL from the preferences
    updateWebServicesUrl();/*from  www.  j  a  v a  2  s .  co m*/

    // Enable / Disable geofencing
    enableGeofencing();

    SDKSettings.setSettingValue(InternalConstants.KEY_PREF_CATALOG,
            StringUtil.replaceIfNull(Hybris.getSharedPreferenceString(InternalConstants.KEY_PREF_CATALOG),
                    SDKSettings.getSettingValue(InternalConstants.KEY_PREF_CATALOG)));

    SDKSettings.setSettingValue(InternalConstants.KEY_PREF_LANGUAGE,
            StringUtil.replaceIfNull(Hybris.getSharedPreferenceString(InternalConstants.KEY_PREF_LANGUAGE),
                    SDKSettings.getSettingValue(InternalConstants.KEY_PREF_LANGUAGE)));

    CookieManager cookieManager = new CookieManager();
    CookieHandler.setDefault(cookieManager);

    populateCategories();

    setDeviceId();
    setUuid(this);
    startService();

}

From source file:at.jclehner.appopsxposed.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.applyTheme(this);
    super.onCreate(savedInstanceState);
    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    if (savedInstanceState == null) {
        getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
    }//from   w  w w . j  a  v  a2s.  c  o  m
}

From source file:dentex.youtube.downloader.AboutActivity.java

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

    this.setTitle(R.string.title_activity_about);

    settings = getSharedPreferences(PREFS_NAME, 0);

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    // Theme init
    Utils.themeInit(this);

    // Language init
    Utils.langInit(this);

    // Load default preferences values
    PreferenceManager.setDefaultValues(this, R.xml.about, false);

    // Display the fragment as the main content.
    getFragmentManager().beginTransaction().replace(android.R.id.content, new AboutFragment()).commit();
    setupActionBar();//from  w ww  . j  ava 2  s.  c  o  m
}

From source file:de.baumann.hhsmoodle.activities.Activity_count.java

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

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    toDo_title = sharedPref.getString("count_title", "");
    String count_title = sharedPref.getString("count_content", "");
    toDo_icon = sharedPref.getString("count_icon", "");
    toDo_create = sharedPref.getString("count_create", "");
    String todo_attachment = sharedPref.getString("count_attachment", "");
    if (!sharedPref.getString("count_seqno", "").isEmpty()) {
        toDo_seqno = Integer.parseInt(sharedPref.getString("count_seqno", ""));
    }//  w ww.j  a  v  a2 s . c om

    setContentView(R.layout.activity_count);
    setTitle(toDo_title);

    final EditText etNewItem = (EditText) findViewById(R.id.etNewItem);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            String itemText = etNewItem.getText().toString();

            if (itemText.isEmpty()) {
                Snackbar.make(lvItems, R.string.todo_enter, Snackbar.LENGTH_LONG).show();
            } else {
                itemsTitle.add(0, itemText);
                itemsCount.add(0, "0");
                etNewItem.setText("");
                writeItemsTitle();
                writeItemsCount();
                lvItems.post(new Runnable() {
                    public void run() {
                        lvItems.setSelection(lvItems.getCount() - 1);
                    }
                });
                adapter.notifyDataSetChanged();
            }
        }
    });

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    helper_main.onStart(Activity_count.this);

    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileTitle());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(count_title);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    try {
        FileOutputStream fOut = new FileOutputStream(newFileCount());
        OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
        myOutWriter.append(todo_attachment);
        myOutWriter.close();

        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }

    lvItems = (ListView) findViewById(R.id.lvItems);
    itemsTitle = new ArrayList<>();
    readItemsTitle();
    readItemsCount();

    adapter = new CustomListAdapter(Activity_count.this, itemsTitle, itemsCount) {
        @NonNull
        @Override
        public View getView(final int position, View convertView, @NonNull ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageButton ib_plus = (ImageButton) v.findViewById(R.id.but_plus);
            ImageButton ib_minus = (ImageButton) v.findViewById(R.id.but_minus);
            TextView tv = (TextView) v.findViewById(R.id.count_count);

            int count = Integer.parseInt(itemsCount.get(position));

            if (count < 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_red));
            } else if (count > 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_green));
            } else if (count == 0) {
                tv.setTextColor(ContextCompat.getColor(Activity_count.this, R.color.color_grey));
            }

            ib_plus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) + 1;
                    String plus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, plus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();

                }
            });

            ib_minus.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    int a = Integer.parseInt(itemsCount.get(position)) - 1;
                    String minus = String.valueOf(a);

                    itemsCount.remove(position);
                    itemsCount.add(position, minus);
                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });

            return v;
        }
    };

    lvItems.setAdapter(adapter);

    lvItems.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(android.widget.AdapterView<?> parent, View view, final int position, long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            AlertDialog.Builder builder = new AlertDialog.Builder(Activity_count.this);
            View dialogView = View.inflate(Activity_count.this, R.layout.dialog_edit_text_singleline_count,
                    null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
            edit_title.setText(title);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTag = edit_title.getText().toString().trim();
                    // Remove the item within array at position
                    itemsTitle.remove(position);
                    itemsCount.remove(position);

                    itemsTitle.add(position, inputTag);
                    itemsCount.add(position, count);

                    // Refresh the adapter
                    adapter.notifyDataSetChanged();
                    // Return true consumes the long click event (marks it handled)
                    writeItemsTitle();
                    writeItemsCount();
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(Activity_count.this, edit_title);
        }
    });

    lvItems.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(android.widget.AdapterView<?> parent, View view, final int position,
                long id) {

            final String title = itemsTitle.get(position);
            final String count = itemsCount.get(position);

            // Remove the item within array at position
            itemsTitle.remove(position);
            itemsCount.remove(position);
            // Refresh the adapter
            adapter.notifyDataSetChanged();
            // Return true consumes the long click event (marks it handled)
            writeItemsTitle();
            writeItemsCount();

            Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG)
                    .setAction(R.string.todo_removed_back, new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            itemsTitle.add(position, title);
                            itemsCount.add(position, count);
                            // Refresh the adapter
                            adapter.notifyDataSetChanged();
                            // Return true consumes the long click event (marks it handled)
                            writeItemsTitle();
                            writeItemsCount();
                        }
                    });
            snackbar.show();

            return true;
        }
    });
}

From source file:net.vexelon.currencybg.app.ui.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   ww w  .  j  a v a  2s  . co  m*/

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView drawerNav = (NavigationView) findViewById(R.id.navView);
    setupDrawerContent(drawerNav);
    drawerToggle = setupDrawerToggle();

    // load default values
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Start Service
    //TODO - temporary commented
    //        startService();
}

From source file:de.baumann.hhsmoodle.popup.Popup_todo.java

private void setTodoList() {

    PreferenceManager.setDefaultValues(Popup_todo.this, R.xml.user_settings, false);
    final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Popup_todo.this);

    NotificationManager nMgr = (NotificationManager) Popup_todo.this
            .getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();/*from  ww w .j  ava2  s.com*/

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "todo_title", "todo_content", "todo_creation" };

    final String search = sharedPref.getString("filter_todo_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "todo_title");
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_todo.this, layoutstyle, row, column,
            xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (todo_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (todo_attachment) {
            case "true":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.alert_circle_red);

                int n = Integer.valueOf(_id);

                android.content.Intent iMain = new android.content.Intent();
                iMain.setAction("shortcutToDo");
                iMain.setClassName(Popup_todo.this, "de.baumann.hhsmoodle.activities.Activity_splash");
                PendingIntent piMain = PendingIntent.getActivity(Popup_todo.this, n, iMain, 0);

                NotificationCompat.Builder builderSummary = new NotificationCompat.Builder(Popup_todo.this)
                        .setSmallIcon(R.drawable.school)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setGroup("HHS_Moodle").setGroupSummary(true).setContentIntent(piMain);

                Notification notification = new NotificationCompat.Builder(Popup_todo.this)
                        .setColor(ContextCompat.getColor(Popup_todo.this, R.color.colorPrimary))
                        .setSmallIcon(R.drawable.school).setContentTitle(todo_title)
                        .setContentText(todo_content).setContentIntent(piMain).setAutoCancel(true)
                        .setGroup("HHS_Moodle")
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(todo_content))
                        .setPriority(Notification.PRIORITY_DEFAULT).setVibrate(new long[0]).build();

                NotificationManager notificationManager = (NotificationManager) Popup_todo.this
                        .getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(n, notification);
                notificationManager.notify(0, builderSummary.build());
                break;
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final Item[] items = {
                            new Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_todo.this,
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(Popup_todo.this)
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "3",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "2",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), todo_title, todo_content, "1",
                                                todo_attachment, todo_creation);
                                        setTodoList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    switch (todo_attachment) {
                    case "true":
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "",
                                todo_creation);
                        setTodoList();
                        break;
                    default:
                        db.update(Integer.parseInt(_id), todo_title, todo_content, todo_icon, "true",
                                todo_creation);
                        setTodoList();
                        break;
                    }
                }
            });
            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            sharedPref.edit().putString("toDo_title", todo_title).apply();
            sharedPref.edit().putString("toDo_text", todo_content).apply();
            sharedPref.edit().putString("toDo_seqno", _id).apply();
            sharedPref.edit().putString("toDo_icon", todo_icon).apply();
            sharedPref.edit().putString("toDo_create", todo_creation).apply();
            sharedPref.edit().putString("toDo_attachment", todo_attachment).apply();

            helper_main.switchToActivity(Popup_todo.this, Activity_todo.class, false);
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String todo_title = row2.getString(row2.getColumnIndexOrThrow("todo_title"));
            final String todo_content = row2.getString(row2.getColumnIndexOrThrow("todo_content"));
            final String todo_icon = row2.getString(row2.getColumnIndexOrThrow("todo_icon"));
            final String todo_attachment = row2.getString(row2.getColumnIndexOrThrow("todo_attachment"));
            final String todo_creation = row2.getString(row2.getColumnIndexOrThrow("todo_creation"));

            final CharSequence[] options = { getString(R.string.bookmark_edit_title),
                    getString(R.string.todo_share), getString(R.string.bookmark_createNote),
                    getString(R.string.bookmark_createEvent), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_todo.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(Popup_todo.this);
                                View dialogView = View.inflate(Popup_todo.this, R.layout.dialog_edit_title,
                                        null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(todo_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, todo_content,
                                                        todo_icon, todo_attachment, todo_creation);
                                                setTodoList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(Popup_todo.this, edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, todo_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, todo_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, todo_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, todo_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setTodoList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                sharedPref.edit().putString("handleTextTitle", todo_title)
                                        .putString("handleTextText", todo_content).apply();
                                helper_main.switchToActivity(Popup_todo.this, Activity_EditNote.class, false);
                            }

                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:com.mobvoi.knowledgegraph.wearcontroltetris.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    PreferenceManager.setDefaultValues(this, R.xml.simple_preferences, true);
    PreferenceManager.setDefaultValues(this, R.xml.advanced_preferences, true);

    /* Create Music */
    sound = new Sound(this);
    sound.startMusic(Sound.MENU_MUSIC, 0);

    /* Database Management */
    Cursor mc;/*from  w w w  .  j  a va2s.  c o  m*/
    datasource = new ScoreDataSource(this);
    datasource.open();
    mc = datasource.getCursor();
    // Use the SimpleCursorAdapter to show the
    // elements in a ListView
    adapter = new SimpleCursorAdapter((Context) this, R.layout.blockinger_list_item, mc,
            new String[] { HighscoreOpenHelper.COLUMN_SCORE, HighscoreOpenHelper.COLUMN_PLAYERNAME },
            new int[] { R.id.text1, R.id.text2 }, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    setListAdapter(adapter);

    /* Create Startlevel Dialog */
    startLevel = 0;
    startLevelDialog = new AlertDialog.Builder(this);
    startLevelDialog.setTitle(R.string.startLevelDialogTitle);
    startLevelDialog.setCancelable(false);
    startLevelDialog.setNegativeButton(R.string.startLevelDialogCancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    startLevelDialog.setPositiveButton(R.string.startLevelDialogStart, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            MainActivity.this.start();
        }
    });

    /* Create Donate Dialog */
    donateDialog = new AlertDialog.Builder(this);
    donateDialog.setTitle(R.string.pref_donate_title);
    donateDialog.setMessage(R.string.pref_donate_summary);
    donateDialog.setNegativeButton(R.string.startLevelDialogCancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    donateDialog.setPositiveButton(R.string.donate_button, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String url = getResources().getString(R.string.donation_url);
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
        }
    });
}

From source file:org.appspot.apprtc.ConnectActivity.java

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

    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_startvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_startvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefCpuUsageDetection = getString(R.string.pref_cpu_usage_detection_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefRoom = getString(R.string.pref_room_key);
    keyprefRoomList = getString(R.string.pref_room_list_key);

    setContentView(R.layout.activity_connect);

    roomEditText = (EditText) findViewById(R.id.room_edittext);
    roomEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override//from  w w w.  j a  v a  2 s .c o  m
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                addRoomButton.performClick();
                return true;
            }
            return false;
        }
    });
    roomEditText.requestFocus();

    roomListView = (ListView) findViewById(R.id.room_listview);
    roomListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    addRoomButton = (ImageButton) findViewById(R.id.add_room_button);
    addRoomButton.setOnClickListener(addRoomListener);
    removeRoomButton = (ImageButton) findViewById(R.id.remove_room_button);
    removeRoomButton.setOnClickListener(removeRoomListener);
    connectButton = (ImageButton) findViewById(R.id.connect_button);
    connectButton.setOnClickListener(connectListener);
    connectLoopbackButton = (ImageButton) findViewById(R.id.connect_loopback_button);
    connectLoopbackButton.setOnClickListener(connectListener);

    // If an implicit VIEW intent is launching the app, go directly to that URL.
    final Intent intent = getIntent();
    if ("android.intent.action.VIEW".equals(intent.getAction()) && !commandLineRun) {
        commandLineRun = true;
        boolean loopback = intent.getBooleanExtra(CallActivity.EXTRA_LOOPBACK, false);
        int runTimeMs = intent.getIntExtra(CallActivity.EXTRA_RUNTIME, 0);
        String room = sharedPref.getString(keyprefRoom, "");
        roomEditText.setText(room);
        connectToRoom(loopback, runTimeMs);
        return;
    }
}