当前位置: 编程技术>移动开发
本页文章导读:
▪音乐播放器 ViewFlipper 滑动银幕 音乐播放器 ViewFlipper 滑动屏幕
main.xml<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" andr.........
▪ 远道刷新界面 service中 RemoteViews textview 远程刷新界面 service中 RemoteViews textview
private void setWidgetText() { RemoteViews views = new RemoteViews(getPackageName(),R.layout.music_widget); views.setTextViewText(R.id.musicname, info); ComponentName thisWidget = new Component.........
▪ 闪光灯手电的实现方式 闪光灯手电筒的实现方式
HTC 野火
直接读写文件
/sys/class/leds/flashlight/brightness
共有四档亮度 [0, 125, 126, 127], 0 为关闭
MOTO 里程碑
直接读写文件
/sys/class/leds/spotlight/brightness
共有三档亮度.........
[1]音乐播放器 ViewFlipper 滑动银幕
来源: 互联网 发布时间: 2014-02-18
音乐播放器 ViewFlipper 滑动屏幕
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/img_single_bg"
android:id="@+id/RelativeLayout_catalog">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/img_playback_bg"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/btn_layout" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_list/index.html"
android:background="#00000000"
android:text="主页"
android:id="@+id/zy"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_lrc/index.html"
android:background="#00000000"
android:text="播放列表"
android:id="@+id/bflb"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_menu/index.html"
android:background="#00000000"
android:text="歌词"
android:id="@+id/gc"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_play/index.html"
android:background="#00000000"
android:text="声音"
android:id="@+id/sy"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="莲莲动听"
android:textSize="16dip"
android:gravity="center"
android:id="@+id/info"
/>
</LinearLayout>
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_layout"
android:layout_alignParentLeft="true"
android:layout_above="@id/seekBar1"
android:id="@+id/flipper"
/>
</RelativeLayout>
在anim内加载进入动作。
主程序调用
private ViewFlipper flipper;
public void onClick(View v) {
View view = flipper.getCurrentView();
Object a = view.getTag();
int b = Integer.valueOf(String.valueOf(a)).intValue();
switch (v.getId()) {
case R.id.zy:
if (b > 1) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 1; i++) {
flipper.showPrevious();
}
}
break;
case R.id.bflb:
if (b > 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 2; i++) {
flipper.showPrevious();
}
} else if (b < 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
flipper.showNext();
}
break;
case R.id.gc:
if (b > 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
flipper.showPrevious();
} else if (b < 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 3 - b; i++) {
flipper.showNext();
}
}
break;
case R.id.sy:
if (b < 4) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 4 - b; i++) {
flipper.showNext();
}
}
break;
}
}
private void initiaView(){
zy = (ImageButton) findViewById(R.id.zy);
bflb = (ImageButton) findViewById(R.id.bflb);
gc = (ImageButton) findViewById(R.id.gc);
sy = (ImageButton) findViewById(R.id.sy);
zy.setOnClickListener(this);
bflb.setOnClickListener(this);
gc.setOnClickListener(this);
sy.setOnClickListener(this);
flipper = (ViewFlipper) findViewById(R.id.flipper);
View view1 = addTextByText("HelloAndroid1");
view1.setTag(1);
View view2 = setList();
view2.setTag(2);
View view3 = setSongWord();
view3.setTag(3);
View view4 = addTextByText("HelloAndroid4");
view4.setTag(4);
flipper.addView(view1);
flipper.addView(view2);
flipper.addView(view3);
flipper.addView(view4);
}
public View addTextByText(String text) {
TextView tv = new TextView(this);
tv.setText(text);
tv.setGravity(1);
return tv;
}
public View setList() {
ListView lv = new ListView(this);
lv.setDrawSelectorOnTop(false);
lv.setCacheColorHint(0);
ListViewAdapter adapter = new ListViewAdapter(this, mMusicList);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// currentListItme = position;
// playMusic();
if (playMusicService != null) {
playMusicService.playMusic(position);
}
}
});
return lv;
}
public View addImageById(int id){
ImageView iv = new ImageView(this);
iv.setImageResource(id);
return iv;
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/img_single_bg"
android:id="@+id/RelativeLayout_catalog">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/img_playback_bg"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/btn_layout" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_list/index.html"
android:background="#00000000"
android:text="主页"
android:id="@+id/zy"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_lrc/index.html"
android:background="#00000000"
android:text="播放列表"
android:id="@+id/bflb"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_menu/index.html"
android:background="#00000000"
android:text="歌词"
android:id="@+id/gc"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/img_buttom_bt_play/index.html"
android:background="#00000000"
android:text="声音"
android:id="@+id/sy"
/>
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="莲莲动听"
android:textSize="16dip"
android:gravity="center"
android:id="@+id/info"
/>
</LinearLayout>
<ViewFlipper
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btn_layout"
android:layout_alignParentLeft="true"
android:layout_above="@id/seekBar1"
android:id="@+id/flipper"
/>
</RelativeLayout>
在anim内加载进入动作。
主程序调用
private ViewFlipper flipper;
public void onClick(View v) {
View view = flipper.getCurrentView();
Object a = view.getTag();
int b = Integer.valueOf(String.valueOf(a)).intValue();
switch (v.getId()) {
case R.id.zy:
if (b > 1) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 1; i++) {
flipper.showPrevious();
}
}
break;
case R.id.bflb:
if (b > 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
for (int i = 0; i < b - 2; i++) {
flipper.showPrevious();
}
} else if (b < 2) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
flipper.showNext();
}
break;
case R.id.gc:
if (b > 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_right_in);
flipper.setOutAnimation(MainActivity.this,
R.anim.push_right_out);
flipper.showPrevious();
} else if (b < 3) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 3 - b; i++) {
flipper.showNext();
}
}
break;
case R.id.sy:
if (b < 4) {
flipper.setInAnimation(MainActivity.this, R.anim.push_left_in);
flipper
.setOutAnimation(MainActivity.this,
R.anim.push_left_out);
for (int i = 0; i < 4 - b; i++) {
flipper.showNext();
}
}
break;
}
}
private void initiaView(){
zy = (ImageButton) findViewById(R.id.zy);
bflb = (ImageButton) findViewById(R.id.bflb);
gc = (ImageButton) findViewById(R.id.gc);
sy = (ImageButton) findViewById(R.id.sy);
zy.setOnClickListener(this);
bflb.setOnClickListener(this);
gc.setOnClickListener(this);
sy.setOnClickListener(this);
flipper = (ViewFlipper) findViewById(R.id.flipper);
View view1 = addTextByText("HelloAndroid1");
view1.setTag(1);
View view2 = setList();
view2.setTag(2);
View view3 = setSongWord();
view3.setTag(3);
View view4 = addTextByText("HelloAndroid4");
view4.setTag(4);
flipper.addView(view1);
flipper.addView(view2);
flipper.addView(view3);
flipper.addView(view4);
}
public View addTextByText(String text) {
TextView tv = new TextView(this);
tv.setText(text);
tv.setGravity(1);
return tv;
}
public View setList() {
ListView lv = new ListView(this);
lv.setDrawSelectorOnTop(false);
lv.setCacheColorHint(0);
ListViewAdapter adapter = new ListViewAdapter(this, mMusicList);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
// currentListItme = position;
// playMusic();
if (playMusicService != null) {
playMusicService.playMusic(position);
}
}
});
return lv;
}
public View addImageById(int id){
ImageView iv = new ImageView(this);
iv.setImageResource(id);
return iv;
}
[2] 远道刷新界面 service中 RemoteViews textview
来源: 互联网 发布时间: 2014-02-18
远程刷新界面 service中 RemoteViews textview
private void setWidgetText() {
RemoteViews views = new RemoteViews(getPackageName(),R.layout.music_widget);
views.setTextViewText(R.id.musicname, info);
ComponentName thisWidget = new ComponentName(this, MusicWidget.class);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
appWidgetManager.updateAppWidget(thisWidget, views);
}
private void setWidgetText() {
RemoteViews views = new RemoteViews(getPackageName(),R.layout.music_widget);
views.setTextViewText(R.id.musicname, info);
ComponentName thisWidget = new ComponentName(this, MusicWidget.class);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
appWidgetManager.updateAppWidget(thisWidget, views);
}
[3] 闪光灯手电的实现方式
来源: 互联网 发布时间: 2014-02-18
闪光灯手电筒的实现方式
HTC 野火
做个试验就明白了。用 adb shell 登录到手机, 使用 echo 命令写入四档亮度的值,观察闪光灯亮度的变化。
HTC 野火
直接读写文件
/sys/class/leds/flashlight/brightness
共有四档亮度 [0, 125, 126, 127], 0 为关闭
MOTO 里程碑直接读写文件
/sys/class/leds/spotlight/brightness共有三档亮度 [0, 100, 255], 0 为关闭 相关文章
- http://www.eoeandroid.com/forum-viewthread-tid-52815.html
- http://www.eoeandroid.com/forum-viewthread-tid-65539.html
- http://www.eoeandroid.com/forum-viewthread-tid-42477.html
- http://www.java2s.com/Open-Source/Android/Barcode/project-destructinator/com/google/zxing/client/android/camera/FlashlightManager.java.htm
- http://code.google.com/p/droidled/
1 楼
pumpkinhua
2011-10-18
楼主能解释的再详细点吗?就用一行代码就可以了吗?
2 楼
shaobin0604
2011-10-19
pumpkinhua 写道
楼主能解释的再详细点吗?就用一行代码就可以了吗?
做个试验就明白了。用 adb shell 登录到手机, 使用 echo 命令写入四档亮度的值,观察闪光灯亮度的变化。
最新技术文章: