欢迎来到传世资源网!
加载中...
正在加载,请耐心等待...
本站为收藏、学习站,如有侵权,请联系管理员删除!

android_实现沉浸式状态栏_

介绍 评论 失效链接反馈

android_实现沉浸式状态栏_ Android平台开发-第1张android_实现沉浸式状态栏_ Android平台开发-第2张android_实现沉浸式状态栏_ Android平台开发-第3张android_实现沉浸式状态栏_ Android平台开发-第4张

/*
 * Copyright (C) 2013 readyState Software Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.readystatesoftware.systembartint.sample;

import static android.content.Intent.ACTION_MAIN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SamplesListActivity extends ListActivity {

	private final IntentAdapter mAdapter = new IntentAdapter();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setListAdapter(mAdapter);
		mAdapter.refresh();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		startActivity(mAdapter.getItem(position));
	}

	private class IntentAdapter extends BaseAdapter {
		private final List<CharSequence> mNames;
		private final Map<CharSequence, Intent> mIntents;

		IntentAdapter() {
			mNames = new ArrayList<CharSequence>();
			mIntents = new HashMap<CharSequence, Intent>();
		}

		void refresh() {
			mNames.clear();
			mIntents.clear();

			final Intent mainIntent = new Intent(ACTION_MAIN, null);
			mainIntent.addCategory("com.readystatesoftware.systembartint.SAMPLE");

			PackageManager pm = getPackageManager();
			final List<ResolveInfo> matches = pm.queryIntentActivities(
					mainIntent, 0);
			for (ResolveInfo match : matches) {
				Intent intent = new Intent();
				intent.setClassName(match.activityInfo.packageName,
						match.activityInfo.name);
				final CharSequence name = match.loadLabel(pm);
				mNames.add(name);
				mIntents.put(name, intent);
			}

			notifyDataSetChanged();
		}

		@Override
		public int getCount() {
			return mNames.size();
		}

		@Override
		public Intent getItem(int position) {
			return mIntents.get(mNames.get(position));
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			TextView tv = (TextView) convertView;
			if (convertView == null) {
				tv = (TextView) LayoutInflater.from(SamplesListActivity.this)
						.inflate(android.R.layout.simple_list_item_1, parent,
								false);
			}
			tv.setText(mNames.get(position));
			return tv;
		}
	}

}

下载声明:

本站资源均有第三方用户自行上传分享推荐,非本站自制,仅供玩家做交流学习之用!切勿用于商业用途!游戏作品版权归原作者享有,如有版权问题,请附带版权证明至邮件,本平台将应您的要求删除。
相关推荐:

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复