Search in sources :

Example 1 with IdRes

use of android.support.annotation.IdRes in project Pix-Art-Messenger by kriztan.

the class ConversationActivity method onBackendConnected.

@Override
void onBackendConnected() {
    if (performRedirectIfNecessary(true)) {
        return;
    }
    xmppConnectionService.getNotificationService().setIsInForeground(true);
    final Intent FirstStartIntent = getIntent();
    final Bundle extras = FirstStartIntent.getExtras();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (extras != null && extras.containsKey(PREF_FIRST_START)) {
            FirstStartTime = extras.getLong(PREF_FIRST_START);
            Log.d(Config.LOGTAG, "Get first start time from StartUI: " + FirstStartTime);
        }
    } else {
        FirstStartTime = System.currentTimeMillis();
        Log.d(Config.LOGTAG, "Device is running Android < SDK 23, no restart required: " + FirstStartTime);
    }
    Intent intent = pendingViewIntent.pop();
    if (intent != null) {
        if (processViewIntent(intent)) {
            if (binding.secondaryFragment != null) {
                notifyFragmentOfBackendConnected(R.id.main_fragment);
            }
            invalidateActionBarTitle();
            return;
        }
    }
    if (FirstStartTime == 0) {
        Log.d(Config.LOGTAG, "First start time: " + FirstStartTime + ", restarting App");
        // write first start timestamp to file
        FirstStartTime = System.currentTimeMillis();
        SharedPreferences FirstStart = getApplicationContext().getSharedPreferences(PREF_FIRST_START, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = FirstStart.edit();
        editor.putLong(PREF_FIRST_START, FirstStartTime);
        editor.commit();
        // restart
        Intent restartintent = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());
        restartintent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        restartintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(restartintent);
        System.exit(0);
    }
    if (xmppConnectionService.getAccounts().size() != 0) {
        if (xmppConnectionService.hasInternetConnection()) {
            if (xmppConnectionService.isWIFI() || (xmppConnectionService.isMobile() && !xmppConnectionService.isMobileRoaming())) {
                if (!xmppConnectionService.installedFromFDroid()) {
                    AppUpdate(xmppConnectionService.installedFromPlayStore());
                }
            }
        }
    }
    for (@IdRes int id : FRAGMENT_ID_NOTIFICATION_ORDER) {
        notifyFragmentOfBackendConnected(id);
    }
    ActivityResult activityResult = postponedActivityResult.pop();
    if (activityResult != null) {
        handleActivityResult(activityResult);
    }
    invalidateActionBarTitle();
    if (binding.secondaryFragment != null && ConversationFragment.getConversation(this) == null) {
        Conversation conversation = ConversationsOverviewFragment.getSuggestion(this);
        if (conversation != null) {
            openConversation(conversation, null);
        }
    }
    showDialogsIfMainIsOverview();
}
Also used : SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) IdRes(android.support.annotation.IdRes) Intent(android.content.Intent) Conversation(de.pixart.messenger.entities.Conversation) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) SuppressLint(android.annotation.SuppressLint)

Example 2 with IdRes

use of android.support.annotation.IdRes in project Osmand by osmandapp.

the class CoordinateInputDialogFragment method setupKeyboardItems.

private void setupKeyboardItems(View keyboardView, View.OnClickListener listener, @IdRes int... itemsIds) {
    @DrawableRes int itemBg = lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg;
    @DrawableRes int controlItemBg = lightTheme ? R.drawable.keyboard_item_control_light_bg : R.drawable.keyboard_item_control_dark_bg;
    ColorStateList clearItemTextColorStateList = AndroidUtils.createColorStateList(getContext(), R.color.keyboard_item_divider_control_color_light, R.color.keyboard_item_divider_control_color_light_pressed);
    ColorStateList numberColorStateList = AndroidUtils.createColorStateList(getContext(), R.color.keyboard_item_text_color_light, R.color.keyboard_item_text_color_light_pressed);
    @ColorInt int textColorDark = getResolvedColor(R.color.keyboard_item_text_color_dark);
    for (@IdRes int id : itemsIds) {
        View itemView = keyboardView.findViewById(id);
        Object item = getItemObjectById(id);
        final boolean controlItem = id == R.id.keyboard_item_next_field || id == R.id.keyboard_item_backspace;
        itemView.setBackgroundResource(controlItem ? controlItemBg : itemBg);
        itemView.setOnClickListener(listener);
        View itemTopSpace = itemView.findViewById(R.id.keyboard_item_top_spacing);
        View itemBottomSpace = itemView.findViewById(R.id.keyboard_item_bottom_spacing);
        TextView itemTv = (TextView) itemView.findViewById(R.id.keyboard_item_text);
        ImageView itemIv = (ImageView) itemView.findViewById(R.id.keyboard_item_image);
        if (item instanceof String) {
            boolean clearItem = id == R.id.keyboard_item_clear;
            if (clearItem) {
                TextViewCompat.setAutoSizeTextTypeWithDefaults(itemTv, TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
                itemTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.default_list_text_size));
            } else {
                TextViewCompat.setAutoSizeTextTypeWithDefaults(itemTv, TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
            }
            if (lightTheme) {
                itemTv.setTextColor(clearItem ? clearItemTextColorStateList : numberColorStateList);
            } else {
                itemTv.setTextColor(clearItem ? getResolvedColor(R.color.keyboard_item_divider_control_color_dark) : textColorDark);
            }
            itemTopSpace.setVisibility(View.VISIBLE);
            itemTv.setVisibility(View.VISIBLE);
            itemTv.setText((String) item);
            itemIv.setVisibility(View.GONE);
            itemBottomSpace.setVisibility(View.VISIBLE);
        } else if (item instanceof Integer) {
            itemTopSpace.setVisibility(View.GONE);
            itemTv.setVisibility(View.GONE);
            itemIv.setVisibility(View.VISIBLE);
            itemBottomSpace.setVisibility(View.GONE);
            Drawable icon;
            if (lightTheme) {
                icon = DrawableCompat.wrap(getResources().getDrawable((Integer) item));
                DrawableCompat.setTintList(icon, numberColorStateList);
            } else {
                icon = getColoredIcon((Integer) item, R.color.keyboard_item_divider_control_color_dark);
            }
            itemIv.setImageDrawable(icon);
        }
    }
}
Also used : DrawableRes(android.support.annotation.DrawableRes) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ColorInt(android.support.annotation.ColorInt) IdRes(android.support.annotation.IdRes) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 3 with IdRes

use of android.support.annotation.IdRes in project Conductor by bluelinelabs.

the class ParentController method addChild.

private void addChild(final int index) {
    @IdRes final int frameId = getResources().getIdentifier("child_content_" + (index + 1), "id", getActivity().getPackageName());
    final ViewGroup container = (ViewGroup) getView().findViewById(frameId);
    final Router childRouter = getChildRouter(container).setPopsLastView(true);
    if (!childRouter.hasRootController()) {
        ChildController childController = new ChildController("Child Controller #" + index, ColorUtil.getMaterialColor(getResources(), index), false);
        childController.addLifecycleListener(new LifecycleListener() {

            @Override
            public void onChangeEnd(@NonNull Controller controller, @NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) {
                if (!isBeingDestroyed()) {
                    if (changeType == ControllerChangeType.PUSH_ENTER && !hasShownAll) {
                        if (index < NUMBER_OF_CHILDREN - 1) {
                            addChild(index + 1);
                        } else {
                            hasShownAll = true;
                        }
                    } else if (changeType == ControllerChangeType.POP_EXIT) {
                        if (index > 0) {
                            removeChild(index - 1);
                        } else {
                            getRouter().popController(ParentController.this);
                        }
                    }
                }
            }
        });
        childRouter.setRoot(RouterTransaction.with(childController).pushChangeHandler(new FadeChangeHandler()).popChangeHandler(new FadeChangeHandler()));
    }
}
Also used : ControllerChangeHandler(com.bluelinelabs.conductor.ControllerChangeHandler) FadeChangeHandler(com.bluelinelabs.conductor.changehandler.FadeChangeHandler) IdRes(android.support.annotation.IdRes) ViewGroup(android.view.ViewGroup) ControllerChangeType(com.bluelinelabs.conductor.ControllerChangeType) Router(com.bluelinelabs.conductor.Router) Controller(com.bluelinelabs.conductor.Controller) BaseController(com.bluelinelabs.conductor.demo.controllers.base.BaseController)

Example 4 with IdRes

use of android.support.annotation.IdRes in project robotcode by OutoftheBoxFTC.

the class ColorListPreference method onPrepareDialogBuilder.

// ----------------------------------------------------------------------------------------------
// Dialog management
// ----------------------------------------------------------------------------------------------
@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    // do NOT call super: we're duplicating and enhancing that impl here
    if (getEntries() == null || getEntryValues() == null || colors == null) {
        throw new IllegalStateException("ColorListPreference: entries, values, and colors required");
    }
    // https://stackoverflow.com/questions/20880841/how-to-add-imageview-array-to-arrayadapter-for-a-listview
    final ArrayList<Pair<CharSequence, Integer>> entryAndColors = new ArrayList<>();
    for (int i = 0; i < getEntries().length; i++) {
        entryAndColors.add(new Pair<CharSequence, Integer>(getEntries()[i], (Integer) colors[i]));
    }
    clickedDialogEntryIndex = getValueIndex();
    // select_dialog_single_choice_holo
    @IdRes final int textViewRes = android.R.id.text1;
    @IdRes final int swatchRes = R.id.colorSwatch;
    @LayoutRes final int layoutRes = R.layout.color_list_preference_line_item;
    ListAdapter adapter = new ArrayAdapter<Pair<CharSequence, Integer>>(getContext(), layoutRes, textViewRes, entryAndColors) {

        @NonNull
        @Override
        public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) {
            if (view == null) {
                view = LayoutInflater.from(getContext()).inflate(layoutRes, parent, false);
            }
            Pair<CharSequence, Integer> pair = getItem(position);
            TextView textView = (TextView) (textViewRes == 0 ? view : view.findViewById(textViewRes));
            textView.setText(pair.first);
            if (swatchRes != 0) {
                ((ImageView) view.findViewById(swatchRes)).setImageDrawable(new ColorDrawable(pair.second));
            }
            return view;
        }
    };
    // builder.setSingleChoiceItems(getEntries(), clickedDialogEntryIndex, new DialogClickListener()); for w/o adapter
    builder.setSingleChoiceItems(adapter, clickedDialogEntryIndex, new DialogClickListener());
    builder.setPositiveButton(null, null);
}
Also used : ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LayoutRes(android.support.annotation.LayoutRes) ColorDrawable(android.graphics.drawable.ColorDrawable) IdRes(android.support.annotation.IdRes) NonNull(android.support.annotation.NonNull) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ListAdapter(android.widget.ListAdapter) ArrayAdapter(android.widget.ArrayAdapter) Nullable(android.support.annotation.Nullable) Pair(android.util.Pair)

Example 5 with IdRes

use of android.support.annotation.IdRes in project anitrend-app by AniTrend.

the class MainActivity method onNavigate.

private void onNavigate(@IdRes int menu) {
    Intent intent;
    switch(menu) {
        case R.id.nav_home_feed:
            mToolbar.setTitle(getString(R.string.drawer_title_home));
            selectedItem = menu;
            mViewPager.setAdapter(new FeedPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_anime:
            mToolbar.setTitle(getString(R.string.drawer_title_anime));
            selectedItem = menu;
            mViewPager.setAdapter(new SeasonPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            mViewPager.setCurrentItem(mPageIndex, false);
            break;
        case R.id.nav_manga:
            mToolbar.setTitle(getString(R.string.drawer_title_manga));
            selectedItem = menu;
            mViewPager.setAdapter(new MangaPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_trending:
            mToolbar.setTitle(getString(R.string.drawer_title_trending));
            selectedItem = menu;
            mViewPager.setAdapter(new TrendingPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_airing:
            mToolbar.setTitle(getString(R.string.drawer_title_airing));
            mViewPager.setAdapter(new AiringPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            selectedItem = menu;
            break;
        case R.id.nav_myanime:
            intent = new Intent(this, MediaListActivity.class);
            intent.putExtra(KeyUtil.arg_mediaType, KeyUtil.ANIME);
            intent.putExtra(KeyUtil.arg_userName, getPresenter().getDatabase().getCurrentUser().getName());
            intent.putExtra(KeyUtil.arg_id, getPresenter().getDatabase().getCurrentUser().getId());
            startActivity(intent);
            break;
        case R.id.nav_mymanga:
            intent = new Intent(this, MediaListActivity.class);
            intent.putExtra(KeyUtil.arg_mediaType, KeyUtil.MANGA);
            intent.putExtra(KeyUtil.arg_userName, getPresenter().getDatabase().getCurrentUser().getName());
            intent.putExtra(KeyUtil.arg_id, getPresenter().getDatabase().getCurrentUser().getId());
            startActivity(intent);
            break;
        case R.id.nav_hub:
            mToolbar.setTitle(getString(R.string.drawer_title_hub));
            mViewPager.setAdapter(new HubPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            selectedItem = menu;
            break;
        case R.id.nav_reviews:
            mToolbar.setTitle(getString(R.string.drawer_title_reviews));
            selectedItem = menu;
            mViewPager.setAdapter(new ReviewPageAdapter(getSupportFragmentManager(), getApplicationContext()));
            mNavigationTabStrip.setViewPager(mViewPager);
            break;
        case R.id.nav_sign_in:
            startActivity(new Intent(MainActivity.this, LoginActivity.class));
            break;
        case R.id.nav_sign_out:
            mBottomSheet = new BottomSheetMessage.Builder().setText(R.string.drawer_signout_text).setTitle(R.string.drawer_signout_title).setPositiveText(R.string.Yes).setNegativeText(R.string.No).buildWithCallback(new BottomSheetChoice() {

                @Override
                public void onPositiveButton() {
                    WebTokenRequest.invalidateInstance(getApplicationContext());
                    Intent intent = new Intent(MainActivity.this, SplashActivity.class);
                    finish();
                    startActivity(intent);
                }

                @Override
                public void onNegativeButton() {
                }
            });
            showBottomSheet();
            break;
        case R.id.nav_check_update:
            switch(ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                case PERMISSION_GRANTED:
                    mBottomSheet = new BottomSheetMessage.Builder().setText(R.string.drawer_update_text).setTitle(R.string.drawer_update_title).setPositiveText(R.string.Yes).setNegativeText(R.string.No).buildWithCallback(new BottomSheetChoice() {

                        @Override
                        public void onPositiveButton() {
                            Version version = getPresenter().getDatabase().getRemoteVersion();
                            if (version != null && version.isNewerVersion())
                                DownloaderService.downloadNewVersion(MainActivity.this, version);
                            else
                                NotifyUtil.createAlerter(MainActivity.this, getString(R.string.title_update_infodadat), getString(R.string.app_no_date), R.drawable.ic_cloud_done_white_24dp, R.color.colorStateGreen);
                        }

                        @Override
                        public void onNegativeButton() {
                        }
                    });
                    showBottomSheet();
                    break;
                case PERMISSION_DENIED:
                    if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE))
                        DialogUtil.createMessage(MainActivity.this, R.string.title_permission_write, R.string.text_permission_write, (dialog, which) -> {
                            switch(which) {
                                case POSITIVE:
                                    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, REQUEST_PERMISSION);
                                    break;
                                case NEGATIVE:
                                    NotifyUtil.makeText(MainActivity.this, R.string.canceled_by_user, Toast.LENGTH_SHORT).show();
                                    break;
                            }
                        });
                    else
                        hasPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    break;
            }
            break;
        case R.id.nav_light_theme:
            getPresenter().getApplicationPref().toggleTheme();
            recreate();
            break;
        default:
            break;
    }
}
Also used : NavigationView(android.support.design.widget.NavigationView) ProfileActivity(com.mxt.anitrend.view.activity.detail.ProfileActivity) Bundle(android.os.Bundle) FeedPageAdapter(com.mxt.anitrend.adapter.pager.index.FeedPageAdapter) Uri(android.net.Uri) SeasonPageAdapter(com.mxt.anitrend.adapter.pager.index.SeasonPageAdapter) BasePresenter(com.mxt.anitrend.presenter.base.BasePresenter) BindView(butterknife.BindView) Manifest(android.Manifest) BottomSheetChoice(com.mxt.anitrend.base.interfaces.event.BottomSheetChoice) User(com.mxt.anitrend.model.entity.anilist.User) NotifyUtil(com.mxt.anitrend.util.NotifyUtil) R(com.mxt.anitrend.R) View(android.view.View) BaseConsumer(com.mxt.anitrend.base.custom.consumer.BaseConsumer) CompatUtil(com.mxt.anitrend.util.CompatUtil) PERMISSION_GRANTED(android.content.pm.PackageManager.PERMISSION_GRANTED) ContextCompat(android.support.v4.content.ContextCompat) NotificationActivity(com.mxt.anitrend.view.activity.detail.NotificationActivity) ThreadMode(org.greenrobot.eventbus.ThreadMode) ActivityCompat(android.support.v4.app.ActivityCompat) Version(com.mxt.anitrend.model.entity.base.Version) DialogUtil(com.mxt.anitrend.util.DialogUtil) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) KeyUtil(com.mxt.anitrend.util.KeyUtil) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) DateUtil(com.mxt.anitrend.util.DateUtil) ButterKnife(butterknife.ButterKnife) ViewPager(android.support.v4.view.ViewPager) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) MenuItem(android.view.MenuItem) GravityCompat(android.support.v4.view.GravityCompat) HeaderImageView(com.mxt.anitrend.base.custom.view.image.HeaderImageView) HubPageAdapter(com.mxt.anitrend.adapter.pager.index.HubPageAdapter) Toast(android.widget.Toast) EventBus(org.greenrobot.eventbus.EventBus) Menu(android.view.Menu) ReviewPageAdapter(com.mxt.anitrend.adapter.pager.index.ReviewPageAdapter) AboutActivity(com.mxt.anitrend.view.activity.base.AboutActivity) DrawerLayout(android.support.v4.widget.DrawerLayout) WebTokenRequest(com.mxt.anitrend.base.custom.async.WebTokenRequest) MediaListActivity(com.mxt.anitrend.view.activity.detail.MediaListActivity) PERMISSION_DENIED(android.content.pm.PackageManager.PERMISSION_DENIED) SettingsActivity(com.mxt.anitrend.view.activity.base.SettingsActivity) ActivityBase(com.mxt.anitrend.base.custom.activity.ActivityBase) DownloaderService(com.mxt.anitrend.service.DownloaderService) IdRes(android.support.annotation.IdRes) MangaPageAdapter(com.mxt.anitrend.adapter.pager.index.MangaPageAdapter) TrendingPageAdapter(com.mxt.anitrend.adapter.pager.index.TrendingPageAdapter) Subscribe(org.greenrobot.eventbus.Subscribe) AvatarIndicatorView(com.mxt.anitrend.base.custom.view.image.AvatarIndicatorView) Toolbar(android.support.v7.widget.Toolbar) UserBase(com.mxt.anitrend.model.entity.base.UserBase) Crashlytics(com.crashlytics.android.Crashlytics) AiringPageAdapter(com.mxt.anitrend.adapter.pager.index.AiringPageAdapter) SmartTabLayout(com.ogaclejapan.smarttablayout.SmartTabLayout) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) BottomSheetMessage(com.mxt.anitrend.view.sheet.BottomSheetMessage) FeedPageAdapter(com.mxt.anitrend.adapter.pager.index.FeedPageAdapter) SeasonPageAdapter(com.mxt.anitrend.adapter.pager.index.SeasonPageAdapter) BottomSheetChoice(com.mxt.anitrend.base.interfaces.event.BottomSheetChoice) Intent(android.content.Intent) MangaPageAdapter(com.mxt.anitrend.adapter.pager.index.MangaPageAdapter) ReviewPageAdapter(com.mxt.anitrend.adapter.pager.index.ReviewPageAdapter) TrendingPageAdapter(com.mxt.anitrend.adapter.pager.index.TrendingPageAdapter) AiringPageAdapter(com.mxt.anitrend.adapter.pager.index.AiringPageAdapter) Version(com.mxt.anitrend.model.entity.base.Version) MediaListActivity(com.mxt.anitrend.view.activity.detail.MediaListActivity) HubPageAdapter(com.mxt.anitrend.adapter.pager.index.HubPageAdapter)

Aggregations

IdRes (android.support.annotation.IdRes)7 View (android.view.View)3 TextView (android.widget.TextView)3 Intent (android.content.Intent)2 TypedArray (android.content.res.TypedArray)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 SharedPreferences (android.content.SharedPreferences)1 PERMISSION_DENIED (android.content.pm.PackageManager.PERMISSION_DENIED)1 PERMISSION_GRANTED (android.content.pm.PackageManager.PERMISSION_GRANTED)1 ColorStateList (android.content.res.ColorStateList)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 ColorInt (android.support.annotation.ColorInt)1