Search in sources :

Example 1 with AppCompatActivity

use of android.support.v7.app.AppCompatActivity in project materialistic by hidroh.

the class FavoriteManagerTest method testLocalItemManager.

@Test
public void testLocalItemManager() {
    ActivityController<AppCompatActivity> controller = Robolectric.buildActivity(AppCompatActivity.class);
    AppCompatActivity activity = controller.create().start().resume().get();
    LocalItemManager.Observer observer = mock(LocalItemManager.Observer.class);
    manager.attach(RuntimeEnvironment.application, activity.getSupportLoaderManager(), observer, null);
    verify(observer).onChanged();
    assertThat(manager.getSize()).isEqualTo(2);
    assertThat(manager.getItem(0).getDisplayedTitle()).contains("ask HN");
    assertThat(manager.getItem(1).getDisplayedTitle()).contains("title");
    manager.detach();
    controller.pause().stop().destroy();
}
Also used : AppCompatActivity(android.support.v7.app.AppCompatActivity) Test(org.junit.Test)

Example 2 with AppCompatActivity

use of android.support.v7.app.AppCompatActivity in project FastAdapter by mikepenz.

the class ExpandableMultiselectDeleteSampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // get RecyclerView
    final RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_collapsible);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter
    fastItemAdapter = new FastItemAdapter<>();
    fastItemAdapter.withPositionBasedStateManagement(false).withSelectable(true).withMultiSelect(true).withSelectOnLongClick(true).withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {

        @Override
        public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            //we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
            Boolean res = mActionModeHelper.onClick(ExpandableMultiselectDeleteSampleActivity.this, item);
            // so that the click listener is not fired
            if (res != null && !res)
                return true;
            return res != null ? res : false;
        }
    }).withOnClickListener(new FastAdapter.OnClickListener<IItem>() {

        @Override
        public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            // check if the actionMode consumes the click. This returns true, if it does, false if not
            if (!mActionModeHelper.isActive())
                Toast.makeText(ExpandableMultiselectDeleteSampleActivity.this, ((SimpleSubItem) item).name + " clicked!", Toast.LENGTH_SHORT).show();
            //                        else
            //                            mFastAdapter.notifyItemChanged(position); // im Bsp. ist das nicht nötig, k.A. warum ich das machen muss!
            mRangeSelectorHelper.onClick();
            return false;
        }
    }).withOnPreLongClickListener(new FastAdapter.OnLongClickListener<IItem>() {

        @Override
        public boolean onLongClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
            boolean actionModeWasActive = mActionModeHelper.isActive();
            ActionMode actionMode = mActionModeHelper.onLongClick((AppCompatActivity) ExpandableMultiselectDeleteSampleActivity.this, position);
            mRangeSelectorHelper.onLongClick(position);
            if (actionMode != null) {
                //we want color our CAB
                ExpandableMultiselectDeleteSampleActivity.this.findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ExpandableMultiselectDeleteSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
                // start the drag selection
                mDragSelectTouchListener.startDragSelection(position);
            }
            //if we have no actionMode we do not consume the event
            return actionMode != null && !actionModeWasActive;
        }
    });
    // provide a custom title provider that even shows the count of sub items
    mActionModeHelper = new ActionModeHelper(fastItemAdapter, R.menu.cab, new ActionBarCallBack()).withTitleProvider(new ActionModeHelper.ActionModeTitleProvider() {

        @Override
        public String getTitle(int selected) {
            return selected + "/" + SubItemUtil.countItems(fastItemAdapter.getItemAdapter(), false);
        }
    }).withSupportSubItems(true);
    // this will take care of selecting range of items via long press on the first and afterwards on the last item
    mRangeSelectorHelper = new RangeSelectorHelper(fastItemAdapter).withSavedInstanceState(savedInstanceState).withActionModeHelper(mActionModeHelper);
    // setup the drag select listener and add it to the RecyclerView
    mDragSelectTouchListener = new DragSelectTouchListener().withSelectListener(new DragSelectTouchListener.OnDragSelectListener() {

        @Override
        public void onSelectChange(int start, int end, boolean isSelected) {
            mRangeSelectorHelper.selectRange(start, end, isSelected, true);
            // we handled the long press, so we reset the range selector
            mRangeSelectorHelper.reset();
        }
    });
    rv.addOnItemTouchListener(mDragSelectTouchListener);
    // do basic RecyclerView setup
    rv.setLayoutManager(new LinearLayoutManager(this));
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //fill with some sample data
    List<IItem> items = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        if (i % 2 == 0) {
            final HeaderSelectionItem expandableItem = new HeaderSelectionItem();
            expandableItem.withSubSelectionProvider(new HeaderSelectionItem.ISubSelectionProvider() {

                @Override
                public int getSelectedSubItems() {
                    return SubItemUtil.countSelectedSubItems(fastItemAdapter, expandableItem);
                }
            }).withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
            //.withIsExpanded(true) don't use this in such a setup, use adapter.expand() to expand all items instead
            //add subitems so we can showcase the collapsible functionality
            List<IItem> subItems = new LinkedList<>();
            for (int ii = 1; ii <= 5; ii++) {
                final SimpleSubItem sampleItem = new SimpleSubItem();
                sampleItem.withName("-- Test " + (i + 1) + "." + ii).withDescription("ID: " + (i + 1) * 100 + ii).withIdentifier((i + 1) * 100 + ii);
                subItems.add(sampleItem);
            }
            expandableItem.withSubItems(subItems);
            items.add(expandableItem);
        } else {
            SimpleSubItem sampleItem = new SimpleSubItem();
            sampleItem.withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
            items.add(sampleItem);
        }
    }
    fastItemAdapter.add(items);
    fastItemAdapter.expand();
    fastItemAdapter.withSelectionListener(new ISelectionListener() {

        @Override
        public void onSelectionChanged(IItem item, boolean selected) {
            if (item instanceof SimpleSubItem) {
                IItem headerItem = ((SimpleSubItem) item).getParent();
                if (headerItem != null) {
                    int pos = fastItemAdapter.getAdapterPosition(headerItem);
                    // Important: notify the header directly, not via the notifyadapterItemChanged!
                    // we just want to update the view and we are sure, nothing else has to be done
                    fastItemAdapter.notifyItemChanged(pos);
                }
            }
        }
    });
    //restore selections (this has to be done after the items were added
    fastItemAdapter.withSavedInstanceState(savedInstanceState);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    // restore action mode
    if (savedInstanceState != null)
        mActionModeHelper.checkActionMode(this);
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ISelectionListener(com.mikepenz.fastadapter.ISelectionListener) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) IItem(com.mikepenz.fastadapter.IItem) IAdapter(com.mikepenz.fastadapter.IAdapter) Toolbar(android.support.v7.widget.Toolbar) SimpleSubItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubItem) RangeSelectorHelper(com.mikepenz.fastadapter_extensions.RangeSelectorHelper) HeaderSelectionItem(com.mikepenz.fastadapter.app.items.HeaderSelectionItem) AppCompatActivity(android.support.v7.app.AppCompatActivity) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) LinkedList(java.util.LinkedList) ActionMode(android.support.v7.view.ActionMode) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) ActionModeHelper(com.mikepenz.fastadapter_extensions.ActionModeHelper) DragSelectTouchListener(com.michaelflisar.dragselectrecyclerview.DragSelectTouchListener)

Example 3 with AppCompatActivity

use of android.support.v7.app.AppCompatActivity in project lottie-android by airbnb.

the class AnimationFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_animation, container, false);
    ButterKnife.bind(this, view);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_back);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getFragmentManager().popBackStack();
        }
    });
    postUpdatePlayButtonText();
    onLoopChanged();
    animationView.addAnimatorListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
            startRecordingDroppedFrames();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            recordDroppedFrames();
            postUpdatePlayButtonText();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            postUpdatePlayButtonText();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            recordDroppedFrames();
            startRecordingDroppedFrames();
        }
    });
    animationView.addAnimatorUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            seekBar.setProgress((int) (animation.getAnimatedFraction() * 100));
        }
    });
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (!animationView.isAnimating()) {
                animationView.setProgress(progress / 100f);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    return view;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) SeekBar(android.widget.SeekBar) AppCompatSeekBar(android.support.v7.widget.AppCompatSeekBar) AppCompatActivity(android.support.v7.app.AppCompatActivity) ValueAnimator(android.animation.ValueAnimator) LottieAnimationView(com.airbnb.lottie.LottieAnimationView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable)

Example 4 with AppCompatActivity

use of android.support.v7.app.AppCompatActivity in project native-navigation by airbnb.

the class NativeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_native, container, false);
    final int count = getArguments().getInt(ARG_COUNT);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    toolbar.setTitle("Fragment " + count);
    toolbar.setNavigationIcon(R.drawable.n2_ic_arrow_back_white);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    view.findViewById(R.id.push).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen(newInstance(count + 1));
        }
    });
    view.findViewById(R.id.present).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Promise promise = new PromiseImpl(new Callback() {

                @Override
                public void invoke(Object... args) {
                    WritableMap map = (WritableMap) args[0];
                    ReadableMap payload = map.getMap("payload");
                    if (payload != null) {
                        String text = "Result: " + payload.getString(RESULT_TEXT);
                        Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
                    }
                }
            }, new Callback() {

                @Override
                public void invoke(Object... args) {
                    Toast.makeText(getContext(), "Promise was rejected.", Toast.LENGTH_LONG).show();
                }
            });
            getScreenCoordinator().presentScreen(newInstance(0), promise);
        }
    });
    view.findViewById(R.id.push_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.present_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().presentScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.pop).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pop();
        }
    });
    final EditText editText = (EditText) view.findViewById(R.id.payload);
    view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Map<String, Object> payload = new HashMap<>();
            payload.put(RESULT_TEXT, editText.getText().toString());
            getScreenCoordinator().dismiss(Activity.RESULT_OK, payload);
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) WritableMap(com.facebook.react.bridge.WritableMap) AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) PromiseImpl(com.facebook.react.bridge.PromiseImpl) Promise(com.facebook.react.bridge.Promise) Callback(com.facebook.react.bridge.Callback) ReadableMap(com.facebook.react.bridge.ReadableMap) ReadableMap(com.facebook.react.bridge.ReadableMap) HashMap(java.util.HashMap) Map(java.util.Map) WritableMap(com.facebook.react.bridge.WritableMap) Toolbar(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Example 5 with AppCompatActivity

use of android.support.v7.app.AppCompatActivity in project remusic by aa112901.

the class FolderDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_common, container, false);
    layoutManager = new LinearLayoutManager(mContext);
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
    recyclerView.setLayoutManager(layoutManager);
    folderDetailAdapter = new FolderDetailAdapter(null);
    recyclerView.setAdapter(folderDetailAdapter);
    setItemDecoration();
    reloadAdapter();
    recyclerView.setHasFixedSize(true);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    ((AppCompatActivity) mContext).setSupportActionBar(toolbar);
    toolbar.setPadding(0, CommonUtils.getStatusHeight(mContext), 0, 0);
    ab = ((AppCompatActivity) mContext).getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.actionbar_back);
    ab.setDisplayHomeAsUpEnabled(true);
    String folder = folder_path.substring(folder_path.lastIndexOf(File.separator), folder_path.length());
    ab.setTitle(folder.substring(folder.lastIndexOf(File.separator) + 1, folder.length()));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mContext.onBackPressed();
        }
    });
    return view;
}
Also used : AppCompatActivity(android.support.v7.app.AppCompatActivity) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) TintImageView(com.bilibili.magicasakura.widgets.TintImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

AppCompatActivity (android.support.v7.app.AppCompatActivity)187 ActionBar (android.support.v7.app.ActionBar)66 View (android.view.View)60 TextView (android.widget.TextView)36 RecyclerView (android.support.v7.widget.RecyclerView)32 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)30 ImageView (android.widget.ImageView)22 Intent (android.content.Intent)19 Bundle (android.os.Bundle)17 Fragment (android.support.v4.app.Fragment)17 Toolbar (android.support.v7.widget.Toolbar)16 Nullable (android.support.annotation.Nullable)15 BindView (butterknife.BindView)14 FragmentTransaction (android.support.v4.app.FragmentTransaction)12 PopupMenu (android.support.v7.widget.PopupMenu)10 LayoutInflater (android.view.LayoutInflater)10 AdapterView (android.widget.AdapterView)10 Activity (android.app.Activity)8 MenuItem (android.view.MenuItem)8 ArrayList (java.util.ArrayList)8