Search in sources :

Example 56 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class FreeVersionDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    OsmandApplication app = (OsmandApplication) getActivity().getApplication();
    app.activateFetchedRemoteParams();
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.OsmandDarkTheme));
    builder.setNegativeButton(R.string.later, null);
    View view = getActivity().getLayoutInflater().inflate(R.layout.free_version_banner, null);
    builder.setView(view);
    dialog = new DownloadActivity.FreeVersionDialog(view, getDownloadActivity(), true);
    dialog.initFreeVersionBanner();
    dialog.expandBanner();
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FreeVersionDialog(net.osmand.plus.download.DownloadActivity.FreeVersionDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) View(android.view.View) DownloadActivity(net.osmand.plus.download.DownloadActivity) NonNull(android.support.annotation.NonNull)

Example 57 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project Osmand by osmandapp.

the class QuickActionsWidget method setupLayout.

private void setupLayout(Context context, int pageCount) {
    OsmandApplication application = ((OsmandApplication) getContext().getApplicationContext());
    boolean light = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
    inflate(new ContextThemeWrapper(context, light ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme), R.layout.quick_action_widget, this);
    container = findViewById(R.id.container);
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(new ViewsPagerAdapter());
    container.setBackgroundResource(light ? R.drawable.bg_card_light : R.drawable.bg_card_dark);
    viewPager.getLayoutParams().height = actions.size() > ELEMENT_PER_PAGE / 2 ? (int) getResources().getDimension(R.dimen.quick_action_widget_height_big) : (int) getResources().getDimension(R.dimen.quick_action_widget_height_small);
    viewPager.requestLayout();
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            updateControls(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    next = (ImageButton) findViewById(R.id.btnNext);
    prev = (ImageButton) findViewById(R.id.btnPrev);
    next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (viewPager.getAdapter().getCount() > viewPager.getCurrentItem() + 1) {
                viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
            }
        }
    });
    prev.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (viewPager.getCurrentItem() - 1 >= 0) {
                viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
            }
        }
    });
    dots = (LinearLayout) findViewById(R.id.dots);
    dots.removeAllViews();
    if (pageCount > 1) {
        int color = light ? R.color.icon_color_light : R.color.white_50_transparent;
        for (int i = 0; i < pageCount; i++) {
            ImageView dot = (ImageView) getLayoutInflater().inflate(R.layout.quick_action_widget_dot, dots, false);
            dot.setImageDrawable(i == 0 ? getIconsCache().getIcon(R.drawable.ic_dot_position, R.color.dashboard_blue) : getIconsCache().getIcon(R.drawable.ic_dot_position, color));
            dots.addView(dot);
        }
    }
    controls = (LinearLayout) findViewById(R.id.controls);
    controls.setVisibility(pageCount > 1 ? VISIBLE : GONE);
    Drawable background = controls.getBackground();
    int backgroundColor = ContextCompat.getColor(context, light ? R.color.dashboard_divider_light : R.color.dashboard_divider_dark);
    if (background instanceof ShapeDrawable) {
        ((ShapeDrawable) background).getPaint().setColor(backgroundColor);
    } else if (background instanceof GradientDrawable) {
        ((GradientDrawable) background).setColor(backgroundColor);
    } else if (background instanceof ColorDrawable) {
        ((ColorDrawable) background).setColor(backgroundColor);
    }
    updateControls(viewPager.getCurrentItem());
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ViewPager(android.support.v4.view.ViewPager) ImageView(android.widget.ImageView) R.id.imageView(net.osmand.plus.R.id.imageView) View(android.view.View) TextView(android.widget.TextView) GradientDrawable(android.graphics.drawable.GradientDrawable) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ImageView(android.widget.ImageView)

Example 58 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project xDrip by NightscoutFoundation.

the class JoH method show_ok_dialog.

public static void show_ok_dialog(final Activity activity, String title, String message, final Runnable runnable) {
    try {
        AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme));
        builder.setTitle(title);
        builder.setMessage(message);
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                // 
                }
                if (runnable != null) {
                    runOnUiThreadDelayed(runnable, 10);
                }
            }
        });
        builder.create().show();
    } catch (Exception e) {
        Log.wtf(TAG, "show_dialog exception: " + e);
        static_toast_long(message);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) DialogInterface(android.content.DialogInterface) GsonBuilder(com.google.gson.GsonBuilder) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 59 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project satstat by mvglasow.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        public void uncaughtException(Thread t, Throwable e) {
            Context c = getApplicationContext();
            File dumpDir = c.getExternalFilesDir(null);
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT);
            fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
            String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis())));
            File dumpFile = new File(dumpDir, fileName);
            PrintStream s;
            try {
                InputStream buildInStream = getResources().openRawResource(R.raw.build);
                s = new PrintStream(dumpFile);
                s.append("SatStat build: ");
                int i;
                try {
                    i = buildInStream.read();
                    while (i != -1) {
                        s.write(i);
                        i = buildInStream.read();
                    }
                    buildInStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                s.append("\n\n");
                e.printStackTrace(s);
                s.flush();
                s.close();
                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(dumpFile);
                mediaScanIntent.setData(contentUri);
                c.sendBroadcast(mediaScanIntent);
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            }
            defaultUEH.uncaughtException(t, e);
        }
    });
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
    prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType);
    prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots);
    prefCoord = Integer.valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord)));
    prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc);
    prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid);
    prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2);
    prefWifiSort = Integer.valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort)));
    prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline);
    prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath);
    ActionBar actionBar = getSupportActionBar();
    setContentView(R.layout.activity_main);
    // Find out default screen orientation
    Configuration config = getResources().getConfiguration();
    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    int rot = wm.getDefaultDisplay().getRotation();
    isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270));
    Log.d(TAG, "isWideScreen=" + Boolean.toString(isWideScreen));
    // Create the adapter that will return a fragment for each of the
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme);
    mTabLayout = new TabLayout(ctx);
    LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mTabLayout.setLayoutParams(mTabLayoutParams);
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        TabLayout.Tab newTab = mTabLayout.newTab();
        newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i));
        mTabLayout.addTab(newTab);
    }
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setCustomView(mTabLayout);
    mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
    // This is needed by the mapsforge library.
    AndroidGraphicFactory.createInstance(this.getApplication());
    // Get system services for event delivery
    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);
    mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);
    mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
    mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
    mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
    mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY);
    mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}
Also used : Configuration(android.content.res.Configuration) FileNotFoundException(java.io.FileNotFoundException) Uri(android.net.Uri) WindowManager(android.view.WindowManager) TabLayout(android.support.design.widget.TabLayout) UncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler) ActionBar(android.support.v7.app.ActionBar) Context(android.content.Context) PrintStream(java.io.PrintStream) LayoutParams(android.view.ViewGroup.LayoutParams) InputStream(java.io.InputStream) Intent(android.content.Intent) IOException(java.io.IOException) Date(java.util.Date) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) LinearLayout(android.widget.LinearLayout)

Example 60 with ContextThemeWrapper

use of android.support.v7.view.ContextThemeWrapper in project MTweaks-KernelAdiutorMOD by morogoku.

the class SettingsFragment method init.

private void init() {
    addPreferencesFromResource(R.xml.settings);
    if (Utils.DONATED) {
        getPreferenceScreen().removePreference(findPreference(KEY_AD_VIEW));
    }
    SwitchPreferenceCompat forceEnglish = (SwitchPreferenceCompat) findPreference(KEY_FORCE_ENGLISH);
    if (Resources.getSystem().getConfiguration().locale.getLanguage().startsWith("en")) {
        getPreferenceScreen().removePreference(forceEnglish);
    } else {
        forceEnglish.setOnPreferenceChangeListener(this);
    }
    /*
        if (Utils.hideStartActivity()) {
            ((PreferenceCategory) findPreference(KEY_USER_INTERFACE))
                    .removePreference(findPreference(KEY_MATERIAL_ICON));
        } else {
            findPreference(KEY_MATERIAL_ICON).setOnPreferenceChangeListener(this);
        }
*/
    findPreference(KEY_RESET_DATA).setOnPreferenceClickListener(this);
    findPreference(KEY_UPDATE_NOTIFICATION).setOnPreferenceChangeListener(this);
    findPreference(KEY_CHECK_UPDATE).setOnPreferenceClickListener(this);
    findPreference(KEY_DARK_THEME).setOnPreferenceChangeListener(this);
    findPreference(KEY_BANNER_RESIZER).setOnPreferenceClickListener(this);
    findPreference(KEY_HIDE_BANNER).setOnPreferenceChangeListener(this);
    findPreference(KEY_ACCENT_COLOR).setOnPreferenceClickListener(this);
    findPreference(KEY_SECTIONS_ICON).setOnPreferenceChangeListener(this);
    findPreference(KEY_APPLY_ON_BOOT_TEST).setOnPreferenceClickListener(this);
    findPreference(KEY_LOGCAT).setOnPreferenceClickListener(this);
    if (Utils.existFile("/proc/last_kmsg") || Utils.existFile("/sys/fs/pstore/console-ramoops")) {
        findPreference(KEY_LAST_KMSG).setOnPreferenceClickListener(this);
    } else {
        ((PreferenceCategory) findPreference(KEY_DEBUGGING_CATEGORY)).removePreference(findPreference(KEY_LAST_KMSG));
    }
    findPreference(KEY_DMESG).setOnPreferenceClickListener(this);
    findPreference(KEY_SET_PASSWORD).setOnPreferenceClickListener(this);
    findPreference(KEY_DELETE_PASSWORD).setOnPreferenceClickListener(this);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || !FingerprintManagerCompat.from(getActivity()).isHardwareDetected()) {
        ((PreferenceCategory) findPreference(KEY_SECURITY_CATEGORY)).removePreference(findPreference(KEY_FINGERPRINT));
    } else {
        mFingerprint = findPreference(KEY_FINGERPRINT);
        mFingerprint.setEnabled(!Prefs.getString("password", "", getActivity()).isEmpty());
    }
    PreferenceCategory sectionsCategory = (PreferenceCategory) findPreference(KEY_SECTIONS);
    for (NavigationActivity.NavigationFragment navigationFragment : NavigationActivity.sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;
        if (fragment != null && fragment.getClass() != SettingsFragment.class) {
            SwitchPreferenceCompat switchPreference = new SwitchPreferenceCompat(new ContextThemeWrapper(getActivity(), R.style.Preference_SwitchPreferenceCompat_Material));
            switchPreference.setSummary(getString(id));
            switchPreference.setKey(fragment.getClass().getSimpleName() + "_enabled");
            switchPreference.setChecked(Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, getActivity()));
            switchPreference.setOnPreferenceChangeListener(this);
            switchPreference.setPersistent(false);
            sectionsCategory.addPreference(switchPreference);
        }
    }
}
Also used : ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) SwitchPreferenceCompat(android.support.v7.preference.SwitchPreferenceCompat) PreferenceCategory(android.support.v7.preference.PreferenceCategory) NavigationActivity(com.moro.mtweaks.activities.NavigationActivity) Fragment(android.support.v4.app.Fragment)

Aggregations

View (android.view.View)41 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)38 ContextThemeWrapper (android.view.ContextThemeWrapper)35 DialogInterface (android.content.DialogInterface)26 Context (android.content.Context)25 AlertDialog (android.support.v7.app.AlertDialog)24 TextView (android.widget.TextView)23 RecyclerView (android.support.v7.widget.RecyclerView)21 ImageView (android.widget.ImageView)21 LayoutInflater (android.view.LayoutInflater)18 Intent (android.content.Intent)13 Nullable (android.support.annotation.Nullable)10 ColorPreferences (me.ccrama.redditslide.ColorPreferences)10 Drawable (android.graphics.drawable.Drawable)9 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)9 EditText (android.widget.EditText)9 Bundle (android.os.Bundle)7 NonNull (android.support.annotation.NonNull)7 ArrayList (java.util.ArrayList)7 SuppressLint (android.annotation.SuppressLint)6