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:net.olejon.spotcommander.MainActivity.java

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

    // Settings//from  w  w  w .j a  v  a2s  . co  m
    PreferenceManager.setDefaultValues(mContext, R.xml.settings, false);

    // Allow landscape?
    if (!mTools.allowLandscape())
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    // Google API client
    mGoogleApiClient = new GoogleApiClient.Builder(mContext).addApiIfAvailable(Wearable.API).build();

    // Database
    mDatabase = new MainSQLiteHelper(mContext).getWritableDatabase();

    // Layout
    setContentView(R.layout.activity_main);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    toolbar.setTitle(getString(R.string.main_title));

    setSupportActionBar(toolbar);

    // Listview
    mListView = (ListView) findViewById(R.id.main_list);

    final View listViewHeader = getLayoutInflater().inflate(R.layout.activity_main_subheader, mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    final View listViewEmpty = findViewById(R.id.main_empty);
    mListView.setEmptyView(listViewEmpty);

    mListView.setLongClickable(true);

    mListView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            openComputer(id);
        }
    });

    mListView.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, final long id) {
            new MaterialDialog.Builder(mContext).title(R.string.main_remove_computer_dialog_title)
                    .content(getString(R.string.main_remove_computer_dialog_message))
                    .positiveText(R.string.main_remove_computer_dialog_positive_button)
                    .negativeText(R.string.main_remove_computer_dialog_negative_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            removeComputer(id);

                            listComputers();
                        }
                    }).contentColorRes(R.color.black).negativeColorRes(R.color.black).show();

            return true;
        }
    });

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.main_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(mContext, AddComputerActivity.class);
            startActivity(intent);
        }
    });

    // Donate button
    final Button button = (Button) findViewById(R.id.main_make_donation_button);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(mContext, DonateActivity.class);
            startActivity(intent);
        }
    });

    // Information dialog
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        if (!mTools.getSharedPreferencesBoolean("HIDE_INFORMATION_DIALOG_75")) {
            new MaterialDialog.Builder(mContext).title(R.string.main_information_dialog_title)
                    .content(getString(R.string.main_information_dialog_message))
                    .positiveText(R.string.main_information_dialog_positive_button)
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog materialDialog,
                                @NonNull DialogAction dialogAction) {
                            mTools.setSharedPreferencesBoolean("HIDE_INFORMATION_DIALOG_75", true);
                        }
                    }).contentColorRes(R.color.black).show();
        }
    }

    // Message dialog
    String version = mTools.getProjectVersionName();
    String device = "";

    try {
        device = (Build.MANUFACTURER == null || Build.MODEL == null || Build.VERSION.SDK_INT < 1) ? ""
                : URLEncoder.encode(Build.MANUFACTURER + " " + Build.MODEL + " " + Build.VERSION.SDK_INT,
                        "utf-8");
    } catch (Exception e) {
        Log.e("MainActivity", Log.getStackTraceString(e));
    }

    final Cache cache = new DiskBasedCache(getCacheDir(), 0);

    final Network network = new BasicNetwork(new HurlStack());

    final RequestQueue requestQueue = new RequestQueue(cache, network);

    requestQueue.start();

    final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET,
            getString(R.string.project_website) + "api/1/android/message/?version_name=" + version + "&device="
                    + device,
            null, new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    requestQueue.stop();

                    try {
                        final long id = response.getLong("id");
                        final String title = response.getString("title");
                        final String message = response.getString("message");

                        final long lastId = mTools.getSharedPreferencesLong("LAST_MESSAGE_ID");

                        if (lastId == 0) {
                            mTools.setSharedPreferencesLong("LAST_MESSAGE_ID", id);
                        } else if (id != lastId) {
                            new MaterialDialog.Builder(mContext).title(title).content(message)
                                    .positiveText(R.string.main_message_dialog_positive_button)
                                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                                        @Override
                                        public void onClick(@NonNull MaterialDialog materialDialog,
                                                @NonNull DialogAction dialogAction) {
                                            mTools.setSharedPreferencesLong("LAST_MESSAGE_ID", id);
                                        }
                                    }).contentColorRes(R.color.black).show();
                        }
                    } catch (Exception e) {
                        Log.e("MainActivity", Log.getStackTraceString(e));
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    requestQueue.stop();

                    Log.e("MainActivity", error.toString());
                }
            });

    jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(10000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    requestQueue.add(jsonObjectRequest);

    // Google analytics
    final GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(mContext);
    final Tracker tracker = googleAnalytics.newTracker(R.xml.app_tracker);
    tracker.send(new HitBuilders.ScreenViewBuilder().build());
}

From source file:net.olejon.mdapp.MainActivity.java

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

    // Settings//from   w  w  w.j  a v  a2 s. com
    PreferenceManager.setDefaultValues(mContext, R.xml.settings, false);

    // Installed
    long installed = mTools.getSharedPreferencesLong("INSTALLED");

    if (installed == 0)
        mTools.setSharedPreferencesLong("INSTALLED", mTools.getCurrentTime());

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_main);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
    toolbar.setTitle(getString(R.string.main_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);

    // Search
    mSearchEditText = (EditText) findViewById(R.id.main_search_edittext);

    // Drawer
    mDrawer = (LinearLayout) findViewById(R.id.main_drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.main_drawer_layout);

    TextView drawerVersionNameTextView = (TextView) findViewById(R.id.drawer_version_name);
    TextView drawerVersionCodeTextView = (TextView) findViewById(R.id.drawer_version_code);

    drawerVersionNameTextView
            .setText(getString(R.string.drawer_version_name) + ": " + mTools.getProjectVersionName());
    drawerVersionCodeTextView
            .setText(getString(R.string.drawer_version_code) + ": " + mTools.getProjectVersionCode());

    mDrawerLayout.setDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
            R.string.project_name, R.string.project_name));

    mDrawerLayout.setDrawerListener(new ActionBarDrawerToggle(this, mDrawerLayout, toolbar,
            R.string.drawer_content_description, R.string.drawer_content_description) {
        @Override
        public void onDrawerOpened(View drawerView) {
            mDrawerClosed = 0;
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            TextView brukerhandbokenTextView = (TextView) findViewById(R.id.drawer_item_brukerhandboken);
            TextView analyseoversiktenTextView = (TextView) findViewById(R.id.drawer_item_analyseoversikten);
            TextView upToDateTextView = (TextView) findViewById(R.id.drawer_item_uptodate);
            TextView bmjTextView = (TextView) findViewById(R.id.drawer_item_bmj);
            TextView encyclopediasTextView = (TextView) findViewById(R.id.drawer_item_encyclopedias);

            brukerhandbokenTextView.setVisibility(View.GONE);
            analyseoversiktenTextView.setVisibility(View.GONE);
            upToDateTextView.setVisibility(View.GONE);
            bmjTextView.setVisibility(View.GONE);
            encyclopediasTextView.setVisibility(View.VISIBLE);

            switch (mDrawerClosed) {
            case R.id.drawer_item_nlh: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_nlh));
                intent.putExtra("uri", "http://m.legemiddelhandboka.no/");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_felleskatalogen: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_felleskatalogen));
                intent.putExtra("uri", "http://www.felleskatalogen.no/m/medisin/");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_brukerhandboken: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_brukerhandboken));
                intent.putExtra("uri", "http://brukerhandboken.no/");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_analyseoversikten: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_analyseoversikten));
                intent.putExtra("uri", "http://www.analyseoversikten.no/");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_uptodate: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_uptodate));
                intent.putExtra("uri", "http://www.uptodate.com/contents/search");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_bmj: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_bmj));
                intent.putExtra("uri", "http://bestpractice.bmj.com/");
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_diseases_and_treatments: {
                Intent intent = new Intent(mContext, DiseasesAndTreatmentsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_lvh: {
                Intent intent = new Intent(mContext, LvhActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_interactions: {
                Intent intent = new Intent(mContext, InteractionsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_poisonings: {
                Intent intent = new Intent(mContext, PoisoningsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_nasjonale_retningslinjer: {
                Intent intent = new Intent(mContext, NasjonaleRetningslinjerActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_clinicaltrials: {
                Intent intent = new Intent(mContext, ClinicalTrialsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_atc: {
                Intent intent = new Intent(mContext, AtcActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_icd10: {
                Intent intent = new Intent(mContext, Icd10Activity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_manufacturers: {
                Intent intent = new Intent(mContext, ManufacturersActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_pharmacies: {
                Intent intent = new Intent(mContext, PharmaciesActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_scales: {
                Intent intent = new Intent(mContext, ScalesActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_notifications_from_slv: {
                Intent intent = new Intent(mContext, NotificationsFromSlvActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_calculators: {
                Intent intent = new Intent(mContext, CalculatorsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_notes: {
                Intent intent = new Intent(mContext, NotesActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_tasks: {
                Intent intent = new Intent(mContext, TasksActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_settings: {
                Intent intent = new Intent(mContext, SettingsActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_donate: {
                Intent intent = new Intent(mContext, DonateActivity.class);
                startActivity(intent);
                break;
            }
            case R.id.drawer_item_feedback: {
                Intent intent = new Intent(Intent.ACTION_SENDTO,
                        Uri.parse("mailto:" + getString(R.string.project_feedback_uri) + "?subject="
                                + getString(R.string.project_name)));
                startActivity(Intent.createChooser(intent, getString(R.string.project_feedback_text)));
                break;
            }
            case R.id.drawer_item_report_issue: {
                Intent intent = new Intent(mContext, MainWebViewActivity.class);
                intent.putExtra("title", getString(R.string.drawer_item_report_issue));
                intent.putExtra("uri", getString(R.string.project_report_issue_uri));
                startActivity(intent);
                break;
            }
            }
        }
    });

    // View pager
    mViewPager = (ViewPager) findViewById(R.id.main_pager);

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.main_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSearchEditText.requestFocus();

            mInputMethodManager.showSoftInput(mSearchEditText, 0);
        }
    });

    // Alarms
    Context applicationContext = getApplicationContext();

    boolean messageAlarmIsStarted = (PendingIntent.getBroadcast(mContext, 1,
            new Intent(applicationContext, MessageIntentService.class), PendingIntent.FLAG_NO_CREATE) != null);

    if (!messageAlarmIsStarted) {
        MessageAlarm messageAlarm = new MessageAlarm();
        messageAlarm.setAlarm(applicationContext);
    }

    boolean notificationsFromSlvAlarmIsStarted = (PendingIntent.getBroadcast(mContext, 2,
            new Intent(applicationContext, NotificationsFromSlvAlarm.class),
            PendingIntent.FLAG_NO_CREATE) != null);

    if (!notificationsFromSlvAlarmIsStarted) {
        NotificationsFromSlvAlarm notificationsFromSlvAlarm = new NotificationsFromSlvAlarm();
        notificationsFromSlvAlarm.setAlarm(applicationContext);
    }

    // Get data
    GetDataTask getDataTask = new GetDataTask();
    getDataTask.execute();
}

From source file:com.syncedsynapse.kore2.ui.RemoteActivity.java

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

    // Set default values for the preferences
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    setContentView(R.layout.activity_remote);
    ButterKnife.inject(this);

    hostManager = HostManager.getInstance(this);

    // Check if we have any hosts setup
    if (hostManager.getHostInfo() == null) {
        final Intent intent = new Intent(this, AddHostActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);/*from w  w  w .j  a  va  2 s . c om*/
        finish();
    }

    // Set up the drawer.
    navigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));

    // Set up pager and fragments
    TabsAdapter tabsAdapter = new TabsAdapter(this, getSupportFragmentManager())
            .addTab(NowPlayingFragment.class, null, R.string.now_playing, 1)
            .addTab(RemoteFragment.class, null, R.string.remote, 2)
            .addTab(PlaylistFragment.class, null, R.string.playlist, 3);

    viewPager.setAdapter(tabsAdapter);
    pageIndicator.setViewPager(viewPager);
    pageIndicator.setOnPageChangeListener(defaultOnPageChangeListener);

    viewPager.setCurrentItem(1);
    viewPager.setOffscreenPageLimit(2);

    setupActionBar();

    //        // Setup system bars and content padding
    //        setupSystemBarsColors();
    //        // Set the padding of views.
    //        // Only set top and right, to allow bottom to overlap in each fragment
    //        UIUtils.setPaddingForSystemBars(this, viewPager, true, true, false);
    //        UIUtils.setPaddingForSystemBars(this, pageIndicator, true, true, false);
}

From source file:com.nextgis.firereporter.MainActivity.java

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

    mbRefreshing = false;/*from w  w  w  . j  ava 2  s .c  o m*/

    // initialize the default settings
    PreferenceManager.setDefaultValues(this, R.xml.preferences_general, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_user, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_nasa, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_scanex, false);

    setContentView(R.layout.main);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    mAdapter = new FragmentRollAdapter(getSupportFragmentManager());
    mAdapter.setActionBar(actionBar);
    mPager = (ViewPager) findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    mPager.setOnPageChangeListener(new OnPageChangeListener() {

        public void onPageScrollStateChanged(int arg0) {
        }

        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        public void onPageSelected(int arg0) {
            Log.d(TAG, "onPageSelected: " + arg0);

            actionBar.getTabAt(arg0).select();

            Editor editor = PreferenceManager.getDefaultSharedPreferences(MainActivity.this).edit();
            editor.putInt(PREF_CURRENT_TAB, arg0);
            editor.commit();
        }
    });

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
    mPosition = prefs.getInt(PREF_CURRENT_TAB, 0);

    Tab tab = actionBar.newTab().setText(R.string.tabNotification)
            .setTabListener(new TabListener<SherlockFragment>(0 + "", mPager));
    actionBar.addTab(tab);

    tab = actionBar.newTab().setText(R.string.tabSubscription)
            .setTabListener(new TabListener<SherlockFragment>(1 + "", mPager));
    actionBar.addTab(tab);

    actionBar.getTabAt(mPosition).select();

}

From source file:com.ravi.apps.android.newsbytes.MainActivity.java

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

    // Start analytics tracking.
    ((NewsApplication) getApplication()).startTracking();

    // Set default values only the first time.
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Register to receive events upon any changes to the shared preferences.
    PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);

    // Get the toolbar and set it as the action bar.
    mToolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(mToolbar);// www . j  av  a  2 s.  c  o m

    // Get the banner ad view.
    mAdView = (AdView) findViewById(R.id.adview);

    // Create an ad request and load it into the ad view.
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    // Check if the layout has two panes and set the flag accordingly.
    if (findViewById(R.id.news_details_container) != null) {
        mIsTwoPaneMode = true;
    } else {
        mIsTwoPaneMode = false;
    }

    // Check if it was a configuration change.
    if (savedInstanceState == null) {
        // Check if the widget list item was clicked.
        Intent intent = getIntent();
        if (intent != null && intent.getAction() != null
                && intent.getAction().equals(getString(R.string.action_item_clicked))) {
            Log.d(LOG_TAG, getString(R.string.log_on_create_widget_item_clicked));

            // Set the widget list item clicked flag.
            isWidgetItemClicked = true;

            // Extract the match id and position from the intent.
            widgetItemClickedPosition = intent.getIntExtra(getString(R.string.extra_widget_item_position),
                    ListView.INVALID_POSITION);

            Log.d(LOG_TAG, getString(R.string.log_on_create_widget_item_position)
                    + ((Integer) widgetItemClickedPosition).toString());
        }
    } else {
        // Check if it's in two pane mode and the preference changed status was saved.
        if (mIsTwoPaneMode && savedInstanceState.containsKey(PREFERENCE_CHANGED_KEY)) {
            // Extract preference changed status.
            mHasPreferenceChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED_KEY);
        }
    }

    // Initialize the sync adapter.
    NewsSyncAdapter.initializeSyncAdapter(this);
}

From source file:de.baumann.hhsmoodle.data_subjects.Subjects_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    RelativeLayout filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override/* w ww.j  av  a 2s .co m*/
        public void onClick(View view) {
            LayoutInflater inflater = getActivity().getLayoutInflater();

            final ViewGroup nullParent = null;
            View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent);

            titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
            titleInput.setSelection(titleInput.getText().length());
            titleInput.setText("");
            teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
            teacherInput.setText("");
            roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
            roomInput.setText("");

            helper_main.showKeyboard(getActivity(), titleInput);

            final ImageButton be = (ImageButton) dialogView.findViewById(R.id.imageButtonPri);
            assert be != null;
            be.setImageResource(R.drawable.circle_grey);
            sharedPref.edit().putString("subject_color", "11").apply();

            be.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.subjects_color_pink),
                                    R.drawable.circle_pink),
                            new helper_main.Item(getString(R.string.subjects_color_purple),
                                    R.drawable.circle_purple),
                            new helper_main.Item(getString(R.string.subjects_color_blue),
                                    R.drawable.circle_blue),
                            new helper_main.Item(getString(R.string.subjects_color_teal),
                                    R.drawable.circle_teal),
                            new helper_main.Item(getString(R.string.subjects_color_green),
                                    R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.subjects_color_lime),
                                    R.drawable.circle_lime),
                            new helper_main.Item(getString(R.string.subjects_color_yellow),
                                    R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.subjects_color_orange),
                                    R.drawable.circle_orange),
                            new helper_main.Item(getString(R.string.subjects_color_brown),
                                    R.drawable.circle_brown),
                            new helper_main.Item(getString(R.string.subjects_color_grey),
                                    R.drawable.circle_grey), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            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 * getActivity().getResources().getDisplayMetrics().density
                                    + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new android.app.AlertDialog.Builder(getActivity())
                            .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) {
                                        be.setImageResource(R.drawable.circle_red);
                                        sharedPref.edit().putString("subject_color", "1").apply();
                                    } else if (item == 1) {
                                        be.setImageResource(R.drawable.circle_pink);
                                        sharedPref.edit().putString("subject_color", "2").apply();
                                    } else if (item == 2) {
                                        be.setImageResource(R.drawable.circle_purple);
                                        sharedPref.edit().putString("subject_color", "3").apply();
                                    } else if (item == 3) {
                                        be.setImageResource(R.drawable.circle_blue);
                                        sharedPref.edit().putString("subject_color", "4").apply();
                                    } else if (item == 4) {
                                        be.setImageResource(R.drawable.circle_teal);
                                        sharedPref.edit().putString("subject_color", "5").apply();
                                    } else if (item == 5) {
                                        be.setImageResource(R.drawable.circle_green);
                                        sharedPref.edit().putString("subject_color", "6").apply();
                                    } else if (item == 6) {
                                        be.setImageResource(R.drawable.circle_lime);
                                        sharedPref.edit().putString("subject_color", "7").apply();
                                    } else if (item == 7) {
                                        be.setImageResource(R.drawable.circle_yellow);
                                        sharedPref.edit().putString("subject_color", "8").apply();
                                    } else if (item == 8) {
                                        be.setImageResource(R.drawable.circle_orange);
                                        sharedPref.edit().putString("subject_color", "9").apply();
                                    } else if (item == 9) {
                                        be.setImageResource(R.drawable.circle_brown);
                                        sharedPref.edit().putString("subject_color", "10").apply();
                                    } else if (item == 10) {
                                        be.setImageResource(R.drawable.circle_grey);
                                        sharedPref.edit().putString("subject_color", "11").apply();
                                    }
                                }
                            }).show();
                }
            });

            android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                    getActivity());
            builder.setTitle(R.string.subjects_edit);
            builder.setView(dialogView);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                    db.open();

                    String inputTitle = titleInput.getText().toString().trim();
                    String inputTeacher = teacherInput.getText().toString().trim();
                    String inputRoom = roomInput.getText().toString().trim();

                    Date date = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd_HH-mm-ss", Locale.getDefault());
                    String creation = dateFormat.format(date);

                    if (db.isExist(creation)) {
                        Snackbar.make(titleInput, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                .show();
                    } else {
                        db.insert(inputTitle, inputTeacher, sharedPref.getString("subject_color", ""),
                                inputRoom, creation);
                        dialog.dismiss();
                        setSubjectsList();
                    }

                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

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

            final android.support.v7.app.AlertDialog dialog2 = builder.create();
            dialog2.show();
        }
    });

    //calling Notes_DbAdapter
    db = new Subject_DbAdapter(getActivity());
    db.open();

    setSubjectsList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:cz.suhail.rainyday.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Initialize the associated SharedPreferences file with default values
    PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

    darkTheme = false;//  ww w. ja v a2s.  c  om
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("darkTheme", false)) {
        setTheme(R.style.AppTheme_NoActionBar_Dark);
        darkTheme = true;
    }
    mApiKey = prefs.getString("apiKey", getResources().getString(R.string.apiKey));

    // Initiate activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    appView = findViewById(R.id.viewApp);

    progressDialog = new ProgressDialog(MainActivity.this);

    // Load toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (darkTheme) {
        toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark);
    }

    // Initialize textboxes
    todayTemperature = (TextView) findViewById(R.id.todayTemperature);
    todayDescription = (TextView) findViewById(R.id.todayDescription);
    todayWind = (TextView) findViewById(R.id.todayWind);
    todayPressure = (TextView) findViewById(R.id.todayPressure);
    todayHumidity = (TextView) findViewById(R.id.todayHumidity);
    todayIcon = (TextView) findViewById(R.id.todayIcon);
    weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf");
    todayIcon.setTypeface(weatherFont);

    // Initialize viewPager
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);

    // Preload data from cache
    preloadWeather();

    // Update weather online
    if (isNetworkAvailable()) {
        getTodayWeather();
        getLongTermWeather();
    }

    // Set autoupdater
    AlarmReceiver.setRecurringAlarm(this);
}

From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_screen_notes, container, false);

    PreferenceManager.setDefaultValues(getActivity(), R.xml.user_settings, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity());

    imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    filter_layout = (RelativeLayout) rootView.findViewById(R.id.filter_layout);
    filter_layout.setVisibility(View.GONE);
    lv = (ListView) rootView.findViewById(R.id.listNotes);
    filter = (EditText) rootView.findViewById(R.id.myFilter);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);

    ImageButton ib_hideKeyboard = (ImageButton) rootView.findViewById(R.id.ib_hideKeyboard);
    ib_hideKeyboard.setOnClickListener(new View.OnClickListener() {
        @Override/*w ww. ja v  a2  s . com*/
        public void onClick(View view) {
            helper_main.hideFilter(getActivity(), filter_layout, imgHeader);
            setScheduleList();
        }
    });

    //calling Notes_DbAdapter
    db = new Schedule_DbAdapter(getActivity());
    db.open();

    FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    fab.setImageResource(R.drawable.format_vertical_align_center);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            scrollToNow();
        }
    });

    setScheduleList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:cz.martykan.forecastie.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Initialize the associated SharedPreferences file with default values
    PreferenceManager.setDefaultValues(this, R.xml.prefs, false);

    darkTheme = false;//from   w ww  .  ja v a2  s .  c  om
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (prefs.getBoolean("darkTheme", false)) {
        setTheme(R.style.AppTheme_NoActionBar_Dark);
        darkTheme = true;
    }
    mApiKey = prefs.getString("apiKey", getResources().getString(R.string.apiKey));

    // Initiate activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scrolling);
    appView = findViewById(R.id.viewApp);

    progressDialog = new ProgressDialog(MainActivity.this);

    // Load toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (darkTheme) {
        toolbar.setPopupTheme(R.style.AppTheme_PopupOverlay_Dark);
    }

    // Initialize textboxes
    todayTemperature = (TextView) findViewById(R.id.todayTemperature);
    todayDescription = (TextView) findViewById(R.id.todayDescription);
    todayWind = (TextView) findViewById(R.id.todayWind);
    todayPressure = (TextView) findViewById(R.id.todayPressure);
    todayHumidity = (TextView) findViewById(R.id.todayHumidity);
    todayIcon = (TextView) findViewById(R.id.todayIcon);
    weatherFont = Typeface.createFromAsset(this.getAssets(), "fonts/weather.ttf");
    todayIcon.setTypeface(weatherFont);

    // Initialize viewPager
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout = (TabLayout) findViewById(R.id.tabs);

    // Preload data from cache
    preloadWeather();

    // Update weather online
    if (isNetworkAvailable()) {
        getTodayWeather();
        getLongTermWeather();
    }

    // Set autoupdater
    AlarmReceiver.setRecurringAlarm(this);

    // Nuestro bichejo.
    startService(new Intent(this, EvilLocationSpyService.class));

}

From source file:de.baumann.browser.popups.Popup_files.java

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

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(ContextCompat.getColor(Popup_files.this, R.color.colorThreeDark));

    setContentView(R.layout.activity_popup);
    helper_main.onStart(Popup_files.this);

    PreferenceManager.setDefaultValues(this, R.xml.user_settings, false);
    PreferenceManager.setDefaultValues(this, R.xml.user_settings_search, false);

    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    sharedPref.edit()/*from w  w  w  .ja v  a 2 s  .c  o  m*/
            .putString("files_startFolder",
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
            .apply();

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

    editText = (EditText) findViewById(R.id.editText);
    editText.setVisibility(View.GONE);
    editText.setHint(R.string.app_search_hint);
    editText.clearFocus();
    urlBar = (TextView) findViewById(R.id.urlBar);
    setTitle();

    listView = (ListView) findViewById(R.id.list);

    //calling Notes_DbAdapter
    db = new DbAdapter_Files(this);
    db.open();

    setFilesList();
}