Java Code Examples for android.widget.listview#setSelector()

The following examples show how to use android.widget.listview#setSelector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectItemQuizView.java    From android-topeka with Apache License 2.0 6 votes vote down vote up
@Override
protected View createQuizContentView() {
    Context context = getContext();
    mListView = new ListView(context);
    mListView.setDivider(null);
    mListView.setSelector(R.drawable.selector_button);
    mListView.setAdapter(
            new OptionsQuizAdapter(getQuiz().getOptions(), R.layout.item_answer_start,
                    context, true));
    mListView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            allowAnswer();
            toggleAnswerFor(position);
        }
    });
    return mListView;
}
 
Example 2
Source File: ToggleTranslateQuizView.java    From android-topeka with Apache License 2.0 6 votes vote down vote up
@Override
protected View createQuizContentView() {
    mListView = new ListView(getContext());
    mListView.setDivider(null);
    mListView.setSelector(R.drawable.selector_button);
    mListView.setAdapter(new OptionsQuizAdapter(getQuiz().getReadableOptions(),
            R.layout.item_answer));
    mListView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            toggleAnswerFor(position);
            if (view instanceof CompoundButton) {
                ((CompoundButton) view).setChecked(mAnswers[position]);
            }

            allowAnswer();
        }
    });
    return mListView;
}
 
Example 3
Source File: SettingsActivity.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void showPreferences() {
	ListView lv = getListView();
	if (lv != null) {
		lv.setBackgroundColor(this.getResources().getColor(R.color.bc_bg_color));
		lv.setCacheColorHint(this.getResources().getColor(R.color.bc_bg_color));
		lv.setSelector(R.drawable.setting_pref_item_background_selector);
		
		ColorDrawable dividerDrawable = new ColorDrawable(this.getResources().getColor(R.color.bc_green_blue_color));
		lv.setDivider(dividerDrawable);
		lv.setDividerHeight(1);
	}
	
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
		addPreferencesFromResource(R.xml.preferences);
	} else {
		loadSettingsFragment();
	}
}
 
Example 4
Source File: FormListFragment.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    List<String> fragmentTitles = mFragmentListSupporter.getListTitles();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_activated_1,
            fragmentTitles.toArray(new String[fragmentTitles.size()]));

    int color = Compat.getColor(getActivity(), R.color.formcolor);
    int[] colors = {0, color, 0};
    ListView listView = getListView();
    listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    listView.setDividerHeight(2);

    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setFocusableInTouchMode(true);
    StateListDrawable selector = new StateListDrawable();
    selector.addState(new int[]{-android.R.attr.state_pressed}, new ColorDrawable(Compat.getColor(getContext(), R.color.main_selection)));
    listView.setSelector(selector);

    setListAdapter(adapter);

    if (fragmentTitles.size() > 0)
        listView.setItemChecked(0, true);
}
 
Example 5
Source File: AbsListContentWindow.java    From NetCloud_android with GNU General Public License v2.0 5 votes vote down vote up
private void initView(Context context){

        mContentView = new FrameLayout(context);

        mListView = new ListView(context);
        mListView.setDividerHeight(ScreenUtils.dp2px(1.5f));
        mListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
        mListView.setSelector(R.drawable.list_item_bg);
        mListView.setBackgroundColor(Color.TRANSPARENT);
        mAdapter = new MyAdapter();

        mContentView.addView(mListView);

        mEmptyView = new TextView(context);
        mEmptyView.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResTools.getDimen(R.dimen.textsize2));
        mEmptyView.setTextColor(ResTools.getColor(R.color.text));
        mEmptyView.setGravity(Gravity.CENTER);
        mEmptyView.setText("empty");
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        lp.topMargin = (int)(ScreenUtils.getScreenSize().y*0.38f);
        mContentView.addView(mEmptyView, lp);

        mLoading = new TextView(context);
        mLoading.setTextSize(TypedValue.COMPLEX_UNIT_PX, ResTools.getDimen(R.dimen.textsize2));
        mLoading.setTextColor(ResTools.getColor(R.color.text));
        mLoading.setText("loading...");
        lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL;
        lp.topMargin = ScreenUtils.getScreenSize().y/3;
        mContentView.addView(mLoading, lp);
    }
 
Example 6
Source File: SuperDialog.java    From SuperDialog with Apache License 2.0 5 votes vote down vote up
/**
 * 列表显示,显示列表屏蔽按钮
 */
private void initListView(ViewGroup viewRoot) {
    listView = new ListView(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    layoutParams.setMargins(dp2px(15), dp2px(5), dp2px(15), dp2px(5));
    listView.setLayoutParams(layoutParams);
    listView.setCacheColorHint(Color.TRANSPARENT);
    listView.setFadingEdgeLength(0);
    listView.setVerticalScrollBarEnabled(false);
    listView.setSelector(new ColorDrawable(Color.TRANSPARENT));
    listView.setDivider(new ColorDrawable(Color.LTGRAY));
    listView.setDividerHeight(dp2px(0.8f));
    if (dialogAdapter == null) {
        dialogAdapter = new ListDialogAdapter();
    }
    listView.setAdapter(dialogAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            dismiss();
            if (listener != null) {
                listener.click(false, position);
            }
        }
    });

    listView.setLayoutAnimation(getLayoutAnimation());
    viewRoot.addView(listView);
}
 
Example 7
Source File: SuperListview.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
protected void initAbsListView(View v) {

    View listView = v.findViewById(android.R.id.list);

    if (listView instanceof ListView)
        mList = (ListView) listView;
    else
        throw new IllegalArgumentException("SuperListView works with a List!");


    if (mList != null) {


        mList.setClipToPadding(mClipToPadding);

        //getList().setDivider(mDivider);
        getList().setDividerHeight((int) mDividerHeight);

        mList.setOnScrollListener(this);
        if (mSelector != 0)
            mList.setSelector(mSelector);

        if (mPadding != -1.0f) {
            mList.setPadding(mPadding, mPadding, mPadding, mPadding);
        } else {
            mList.setPadding(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom);
        }

        if (mScrollbarStyle != -1)
            mList.setScrollBarStyle(mScrollbarStyle);
    }
}
 
Example 8
Source File: TopicsListFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView listView = getListView();
    if (!Utils.isTablet(getActivity())) {
        // TODO ...
        // view.setBackgroundColor(getResources().getColor(R.color.plus_stream_spacer_color));
    }

    if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) {
        int verticalMargin = getResources().getDimensionPixelSize(R.dimen.topics_list_padding_vertical);
        if (verticalMargin > 0) {
            listView.setClipToPadding(false);
            listView.setPadding(0, verticalMargin, 0, verticalMargin);
        }
    }

    listView.setOnScrollListener(this);
    listView.setDrawSelectorOnTop(true);
    // listView.setDivider(getResources().getDrawable(android.R.color.transparent));
    // listView.setDividerHeight(getResources()
    // .getDimensionPixelSize(R.dimen.page_margin_width));

    TypedValue v = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.clickableItemBackground, v, true);
    listView.setSelector(v.resourceId);

    setListAdapter(mAdapter);
}
 
Example 9
Source File: NormalListDialog.java    From SprintNBA with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mTvTitle.setSingleLine(true);
    mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));

    ll_container.addView(mTvTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    return ll_container;
}
 
Example 10
Source File: ThemeUtil.java    From YiBo with Apache License 2.0 5 votes vote down vote up
public static void setListViewStyle(ListView listView) {
	if (listView == null) {
		return;
	}
	Theme theme = ThemeUtil.createTheme(listView.getContext());
	listView.setDivider(theme.getDrawable("line_seperator"));
	listView.setSelector(theme.getDrawableByColor("selector_list_item"));
}
 
Example 11
Source File: CategoriesFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final ListView listView = getListView();
    if (!Utils.isTablet(getActivity())) {
        // TODO ...
        // view.setBackgroundColor(getResources().getColor(R.color.plus_stream_spacer_color));
    }

    if (getArguments() != null && getArguments().getBoolean(EXTRA_ADD_VERTICAL_MARGINS, false)) {
        int verticalMargin = getResources().getDimensionPixelSize(R.dimen.categories_list_padding_vertical);
        if (verticalMargin > 0) {
            listView.setClipToPadding(false);
            listView.setPadding(0, verticalMargin, 0, verticalMargin);
        }
    }

    listView.setDrawSelectorOnTop(true);
    // listView.setDivider(getResources().getDrawable(android.R.color.transparent));
    // listView.setDividerHeight(getResources()
    // .getDimensionPixelSize(R.dimen.page_margin_width));

    TypedValue v = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.clickableItemBackground, v, true);
    listView.setSelector(v.resourceId);

    setListAdapter(mAdapter);
}
 
Example 12
Source File: NormalListDialog.java    From FlycoDialog_Master with MIT License 5 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mTvTitle.setSingleLine(true);
    mTvTitle.setPadding(dp2px(18), dp2px(10), 0, dp2px(10));

    ll_container.addView(mTvTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    return ll_container;
}
 
Example 13
Source File: SampleActivity.java    From RippleDrawable with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);

    mListView = (ListView) findViewById(R.id.list);
    mListView.setSelector(getDrawable2(R.drawable.list_selector));
    mListView.setAdapter(new ListAdapter());

    mActionButton = (FloatingActionButton) findViewById(R.id.fab);
    mActionButton.setBackgroundDrawable(getDrawable2(R.drawable.fab_background));
    mActionButton.setClickable(true);
    mActionButton.setOnTouchListener(
            new DrawableHotspotTouch((LollipopDrawable) mActionButton.getBackground()));
}
 
Example 14
Source File: UIDataSelector.java    From Auie with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 构建内容视图
 * @return 内容视图
 */
private View createContentView(){
	rootContainer = new LinearLayout(context);
	rootContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	rootContainer.setBackgroundColor(backgroundColor);
	rootContainer.setOrientation(LinearLayout.VERTICAL);
	topLineView = new View(context);
	topLineView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int)(topLineHeight * DP)));
	topLineView.setBackgroundColor(topLineColor);
	dataContainer = new LinearLayout(context);
	dataContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	dataContainer.setOrientation(LinearLayout.HORIZONTAL);
	dataContainer.setGravity(Gravity.CENTER);
	int paddingPixel = (int)(padding * DP);
	switch (mode) {
	case 3:
		thirdListView = new ListView(context);
		thirdListView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
		thirdListView.setPadding(paddingPixel, paddingPixel, paddingPixel, paddingPixel);
		thirdListView.setSelector(new ColorDrawable(Color.TRANSPARENT));
		thirdListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
		thirdListView.setOnItemClickListener(itemClickListener);
		thirdListView.setAdapter(dataAdapters.get(2));
		thirdListView.setTag(dataAdapters.get(2));
	case 2:
		secondListView = new ListView(context);
		secondListView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
		secondListView.setPadding(paddingPixel, paddingPixel, paddingPixel, paddingPixel);
		secondListView.setSelector(new ColorDrawable(Color.TRANSPARENT));
		secondListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
		secondListView.setOnItemClickListener(itemClickListener);
		secondListView.setAdapter(dataAdapters.get(1));
		secondListView.setTag(dataAdapters.get(1));
	case 1:
		fristListView = new ListView(context);
		fristListView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
		fristListView.setPadding(paddingPixel, paddingPixel, paddingPixel, paddingPixel);
		fristListView.setSelector(new ColorDrawable(Color.TRANSPARENT));
		fristListView.setDivider(new ColorDrawable(Color.TRANSPARENT));
		fristListView.setOnItemClickListener(itemClickListener);
		fristListView.setAdapter(dataAdapters.get(0));
		fristListView.setTag(dataAdapters.get(0));
		break;
	default:
		break;
	}
	
	dataContainer.addView(fristListView);
	if (secondListView != null) {
		leftLineView = new View(context);
		leftLineView.setLayoutParams(new LayoutParams((int)(leftLineWidth * DP), LayoutParams.MATCH_PARENT));
		leftLineView.setBackgroundColor(leftLineColor);
		dataContainer.addView(leftLineView);
		dataContainer.addView(secondListView);
	}
	if (thirdListView != null) {
		rightLineView = new View(context);
		rightLineView.setLayoutParams(new LayoutParams((int)(rightLineWidth * DP), LayoutParams.MATCH_PARENT));
		rightLineView.setBackgroundColor(rightLineColor);
		dataContainer.addView(rightLineView);
		dataContainer.addView(thirdListView);
	}
	rootContainer.addView(topLineView);
	rootContainer.addView(dataContainer);
	
	return rootContainer;
}
 
Example 15
Source File: ActionSheetDialog.java    From AutoTest with MIT License 4 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);
    ll_container.setBackgroundColor(Color.TRANSPARENT);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setGravity(Gravity.CENTER);
    mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.topMargin = dp2px(20);

    ll_container.addView(mTvTitle, params);

    /** title underline */
    mVLineTitle = new View(mContext);
    ll_container.addView(mVLineTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    /** mCancel btn */
    mTvCancel = new TextView(mContext);
    mTvCancel.setGravity(Gravity.CENTER);
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.topMargin = dp2px(7);
    lp.bottomMargin = dp2px(7);
    mTvCancel.setLayoutParams(lp);

    ll_container.addView(mTvCancel);

    return ll_container;
}
 
Example 16
Source File: ListViewSelectorPaint.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(View view, Object value) {
    ListView listView = (ListView) view;
    listView.setSelector((Drawable) value);
}
 
Example 17
Source File: MultiSelectEditText.java    From AutoCompleteBubbleText with Apache License 2.0 4 votes vote down vote up
/**
 * Override this to customize the ListView
 * @return a custom ListView
 */
protected ListView onCreateListView(){
    ListView lv = new ListView(getContext());
    lv.setSelector(R.drawable.selector_list_checked);
    return lv;
}
 
Example 18
Source File: ActionSheetDialog.java    From SprintNBA with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);
    ll_container.setBackgroundColor(Color.TRANSPARENT);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setGravity(Gravity.CENTER);
    mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.topMargin = dp2px(20);

    ll_container.addView(mTvTitle, params);

    /** title underline */
    mVLineTitle = new View(mContext);
    ll_container.addView(mVLineTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    /** mCancel btn */
    mTvCancel = new TextView(mContext);
    mTvCancel.setGravity(Gravity.CENTER);
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.topMargin = dp2px(7);
    lp.bottomMargin = dp2px(7);
    mTvCancel.setLayoutParams(lp);

    ll_container.addView(mTvCancel);

    return ll_container;
}
 
Example 19
Source File: ActionSheetDialog.java    From RecordVideo with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView() {
    LinearLayout ll_container = new LinearLayout(mContext);
    ll_container.setOrientation(LinearLayout.VERTICAL);
    ll_container.setBackgroundColor(Color.TRANSPARENT);

    /** title */
    mTvTitle = new TextView(mContext);
    mTvTitle.setGravity(Gravity.CENTER);
    mTvTitle.setPadding(dp2px(10), dp2px(5), dp2px(10), dp2px(5));

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    params.topMargin = dp2px(20);

    ll_container.addView(mTvTitle, params);

    /** title underline */
    mVLineTitle = new View(mContext);
    ll_container.addView(mVLineTitle);

    /** listview */
    mLv = new ListView(mContext);
    mLv.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1));
    mLv.setCacheColorHint(Color.TRANSPARENT);
    mLv.setFadingEdgeLength(0);
    mLv.setVerticalScrollBarEnabled(false);
    mLv.setSelector(new ColorDrawable(Color.TRANSPARENT));

    ll_container.addView(mLv);

    TextView cancelDivider = new TextView(mContext);
    cancelDivider.setGravity(Gravity.CENTER);
    cancelDivider.setBackgroundColor(Color.parseColor("#ffefefef"));
    LayoutParams clp = new LayoutParams(LayoutParams.MATCH_PARENT, 20);
    cancelDivider.setLayoutParams(clp);
    ll_container.addView(cancelDivider);
    /** mCancel btn */
    mTvCancel = new TextView(mContext);
    mTvCancel.setGravity(Gravity.CENTER);
    LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    lp.topMargin = dp2px(0);
    lp.bottomMargin = dp2px(0);
    mTvCancel.setLayoutParams(lp);

    ll_container.addView(mTvCancel);

    return ll_container;
}
 
Example 20
Source File: PhotoAlbumPickerActivity.java    From KrGallery with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
    actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR);
    // actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setBackText(context.getString(R.string.Cancel));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == 1) {
                if (delegate != null) {
                    finishFragment(false);
                    delegate.startPhotoSelectActivity();
                }
            } else if (id == item_photos) {
                refreshShowPic();//刷新照片目录
            } else if (id == item_video) {
                refreshShowVedio();//刷新录像目录
            }
        }
    });


    fragmentView = new FrameLayout(context);

    FrameLayout frameLayout = (FrameLayout) fragmentView;
    frameLayout.setBackgroundColor(DarkTheme ? 0xff000000 : 0xffffffff);
    //==============videos pick====================
    int res = !singlePhoto && filterMimeTypes.length > 0 ? R.string.PickerVideo : R.string.Album;
    actionBar.setTitle(context.getString(res));
    selectedMode = filterMimeTypes.length > 0 ? 1 : selectedMode;
    listView = new ListView(context);
    listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4),
            AndroidUtilities.dp(4));
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setSelector(new ColorDrawable(0));
    listView.setDividerHeight(0);
    listView.setDivider(null);
    listView.setDrawingCacheEnabled(false);
    listView.setScrollingCacheEnabled(false);
    frameLayout.addView(listView);
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView
            .getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    // layoutParams.bottomMargin = AndroidUtilities.dp(48);
    listView.setLayoutParams(layoutParams);
    listView.setAdapter(listAdapter = new ListAdapter(context));
    AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);

    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setText(R.string.NoPhotos);
    frameLayout.addView(emptyView);
    layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    emptyView.setLayoutParams(layoutParams);
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    progressView = new FrameLayout(context);
    progressView.setVisibility(View.GONE);
    frameLayout.addView(progressView);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(48);
    progressView.setLayoutParams(layoutParams);

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar);
    layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.gravity = Gravity.CENTER;
    progressView.setLayoutParams(layoutParams);


    if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
        progressView.setVisibility(View.VISIBLE);
        listView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.GONE);
        listView.setEmptyView(emptyView);
    }
    return fragmentView;
}