zoukankan      html  css  js  c++  java
  • 生成桌面插件

    package org.app.qqmusicplayer;
    
    import android.app.PendingIntent;
    import android.appwidget.AppWidgetManager;
    import android.appwidget.AppWidgetProvider;
    import android.content.ComponentName;
    import android.content.Context;
    import android.content.Intent;
    import android.util.Log;
    import android.widget.RemoteViews;
    
    public class AppWidget extends AppWidgetProvider {
        private static final String PLAY_ACTION = "com.app.playmusic";
        private static final String NEXT_ACTION = "com.app.nextone";
        private static final String lAST_ACTION = "com.app.lastone";
        private static final String START_APP = "com.app.startapp";
        @Override
        public void onDeleted(Context context, int[] appWidgetIds) {
            Log.i("info", "onDeleted...");
            super.onDeleted(context, appWidgetIds);
        }
    
        @Override
        public void onDisabled(Context context) {
            Log.i("info", "onDisabled...");
            super.onDisabled(context);
        }
    
        @Override
        public void onEnabled(Context context) {
            Log.i("info", "onEnabled...");
            super.onEnabled(context);
        }
    
        @Override
        public void onReceive(Context context, Intent intent) {
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidgetlayout);
            if (intent.getAction().equals("com.app.pause")){
                views.setImageViewResource(R.id.playButton, R.drawable.play_button);
            } else if (intent.getAction().equals("com.app.play")){
                views.setImageViewResource(R.id.playButton, R.drawable.pause_button);
            } else if (intent.getAction().equals("com.app.musictitle")){
                String musicName = intent.getExtras().getString("title");
                if (musicName.length()>6){
                    musicName = musicName.substring(0, 5)+"...";
                }
                views.setTextViewText(R.id.title, musicName);
            }
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); 
            ComponentName componentName = new ComponentName(context,AppWidget.class); 
            appWidgetManager.updateAppWidget(componentName, views);
            Log.i("info", "onReceive...");
            super.onReceive(context, intent);
        }
    
        @Override
        public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                int[] appWidgetIds) {
            Log.i("info", "onUpdate...");
            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidgetlayout);
            /**设置播放键的动作*/
            views.setImageViewResource(R.id.playButton, R.drawable.play_button);
            Intent playIntent = new Intent(PLAY_ACTION);
            PendingIntent playPending = PendingIntent.getBroadcast(context, 0, playIntent, 0);
            views.setOnClickPendingIntent(R.id.playButton, playPending);
            /**设置上一首按钮的动作*/
            Intent lastIntent = new Intent(lAST_ACTION);
            PendingIntent lastPending = PendingIntent.getBroadcast(context, 0, lastIntent, 0);
            views.setOnClickPendingIntent(R.id.lastButton, lastPending);
            /**设置下一首按钮的动作*/
            Intent nextIntent = new Intent(NEXT_ACTION);
            PendingIntent nextPending = PendingIntent.getBroadcast(context, 0, nextIntent, 0);
            views.setOnClickPendingIntent(R.id.nextButton, nextPending);
            
            /**获取正在播放的音乐名*/
            Intent intent = new Intent();
            intent.setAction(START_APP);
            context.sendBroadcast(intent);
            
            appWidgetManager.updateAppWidget(appWidgetIds, views);
        }
    
    }
  • 相关阅读:
    阿里HBase高可用8年“抗战”回忆录
    Service Mesh 初体验
    阿里云HBase推出普惠性高可用服务,独家支持用户的自建、混合云环境集群
    Ververica Platform-阿里巴巴全新Flink企业版揭秘
    深度 | 带领国产数据库走向世界,POLARDB底层逻辑是什么?
    AI加持的阿里云飞天大数据平台技术揭秘
    Nacos 常见问题及解决方法
    数据上云,应该选择全量抽取还是增量抽取?
    一文带你了解 Flink Forward 柏林站全部重点内容
    Oracle数据库中序列(SEQUENCE)的用法详解
  • 原文地址:https://www.cnblogs.com/ct732003684/p/2853371.html
Copyright © 2011-2022 走看看