当前位置:  编程技术>移动开发
本页文章导读:
    ▪ubuntu wine 装配source insight        ubuntu wine 安装source insight 1 sudo apt-get install wine下载souceinsight 3.52 wine Si3566Setup.exe3 序列号(Serial):(任选其一)SI3US-956386-80191SI3US-840598-11493SI3US-404808-04697SI3US-510811-93484SI3US-343066-11287启动wine "c:\Pr.........
    ▪ 长按home键展示当前任务        长按home键显示当前任务 公司给我的任务就是怎么长按home键显示当前任务,刚开始我还以为利用一个activity开启一个service就行啦,然后在监听home键,但是监听到了home键,也是不能在service中.........
    ▪ 多线程断点上传下载种       多线程断点上传下载类 public class MulThreadDownload { /** * @param args */ public static void main(String[] args) { String path = "http://net.itcast.cn/QQWubiSetup.exe"; try { new MulThreadDownload().download(path, 3); } catch (Except.........

[1]ubuntu wine 装配source insight
    来源: 互联网  发布时间: 2014-02-18
ubuntu wine 安装source insight
1 sudo apt-get install wine
下载souceinsight 3.5

2 wine Si3566Setup.exe

3 序列号(Serial):(任选其一)
SI3US-956386-80191
SI3US-840598-11493
SI3US-404808-04697
SI3US-510811-93484
SI3US-343066-11287


启动
wine "c:\Program Files\Source Insight 3\Insight3.exe"

可以用脚本
bash source.sh

source.sh内容为:
wine "c:\Program Files\Source Insight 3\Insight3.exe"

    
[2] 长按home键展示当前任务
    来源: 互联网  发布时间: 2014-02-18
长按home键显示当前任务

公司给我的任务就是怎么长按home键显示当前任务,刚开始我还以为利用一个activity开启一个service就行啦,然后在监听home键,但是监听到了home键,也是不能在service中显示一个view的,view是建立activity的基础上才能显示的,所以必须在一个activity中监听到home键的长按才行,所以最终只能在Launcher中监听home键的长按才行,那怎么监听home键的长按呢,其实我现在想到了两种办法,第一种是监听logcat消息日志,因为每次按下home键都会发送一个系统日志;第二种方法就是在Launcher中监听home键,方法在我的日志中。接着就是要重写一个dialog按钮,然后在里面显示最近用的应用程序,dialog的代码如下:

public class RecentApplicationsDialog extends Dialog implements OnClickListener {
    // Elements for debugging support
    private static final String LOG_TAG = "RecentApplicationsDialog";
    private static final boolean DBG_FORCE_EMPTY_LIST = false;

    private static final int NUM_BUTTONS = 8;
    private static final int MAX_RECENT_TASKS = NUM_BUTTONS * 2;    // allow for some discards
    private int mIconSize;
    
    //public  static boolean RecentDialog_First = false ;	// ratation flag
    
    final TextView[] mIcons = new TextView[NUM_BUTTONS];
    View mNoAppsText;
    IntentFilter mBroadcastIntentFilter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);

    Handler mHandler = new Handler();

    Runnable mCleanup = new Runnable() {
        public void run() {
            // dump extra memory we're hanging on to
            for (TextView icon: mIcons) {
                icon.setCompoundDrawables(null, null, null, null);
                icon.setTag(null);
            }
        }
    };

   

    public RecentApplicationsDialog(Context context) {
        super(context, R.style.RecentApplicationsDialog);
        final Resources resources = context.getResources();
        mIconSize = (int) resources.getDimension(R.dimen.app_icon_size);
    }

    /**
     * We create the recent applications dialog just once, and it stays around (hidden)
     * until activated by the user.
     *
     * @see PhoneWindowManager#showRecentAppsDialog
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 
        Context context = getContext();
        
        
        
        Window window = getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        //window.setType(WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG);
        window.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);//导致界面里面所有需要弹出软键盘的控件均无法显示软键盘
        //window.setTitle("Recents");

        setContentView(R.layout.recent_apps_dialog);

        final WindowManager.LayoutParams params = window.getAttributes();
        params.dimAmount = 0.5f;//设置透明度(范围是0~1.0f)
        
		DisplayMetrics display = new DisplayMetrics();  
		window.getWindowManager().getDefaultDisplay().getMetrics(display);

		WindowManager wm = (WindowManager)context.getSystemService(context.WINDOW_SERVICE);
		Display display_rotation = wm.getDefaultDisplay();

		params.width = WindowManager.LayoutParams.MATCH_PARENT;
    	params.height = WindowManager.LayoutParams.MATCH_PARENT;

        window.setAttributes(params);
        window.setFlags(0, WindowManager.LayoutParams.FLAG_DIM_BEHIND);//遮罩式(模式)顶级窗口--该顶级view下的部件被遮住,不可以操作
        
        
        
        mIcons[0] = (TextView)findViewById(R.id.button01);
        mIcons[1] = (TextView)findViewById(R.id.button02);
        mIcons[2] = (TextView)findViewById(R.id.button03);
        mIcons[3] = (TextView)findViewById(R.id.button04);
        mIcons[4] = (TextView)findViewById(R.id.button05);
        mIcons[5] = (TextView)findViewById(R.id.button06);
        mIcons[6] = (TextView)findViewById(R.id.button07);
        mIcons[7] = (TextView)findViewById(R.id.button08);
        
        mNoAppsText = findViewById(R.id.no_applications_message);

        for (TextView b: mIcons) {
            b.setOnClickListener(this);
        }
        
    }

    /**
     * Handler for user clicks.  If a button was clicked, launch the corresponding activity.
     */
    public void onClick(View v) {
        for (TextView b: mIcons) {
            if (b == v) {
                // prepare a launch intent and send it
                Intent intent = (Intent)b.getTag();
                if (intent != null) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
                    try {
                        getContext().startActivity(intent);
                    } catch (ActivityNotFoundException e) {
                        Log.w("Recent", "Unable to launch recent task", e);
                    }
                }
                break;
            }
        }
        dismiss();
    }

    /**
     * Set up and show the recent activities dialog.
     */
    @Override
    public void onStart() {
        super.onStart();
        reloadButtons();
        //注册广播
        getContext().registerReceiver(mBroadcastReceiver, mBroadcastIntentFilter);
        //Activity不进行icons初始化工作
        mHandler.removeCallbacks(mCleanup);
    }

    /**
     * Dismiss the recent activities dialog.
     */
    @Override
    public void onStop() {
        super.onStop();
        // stop receiving broadcasts
        getContext().unregisterReceiver(mBroadcastReceiver);

        mHandler.postDelayed(mCleanup, 100);
     }


    /**
     * Reload the 6 buttons with recent activities
     */
    private void reloadButtons() {

        final Context context = getContext();
        
        final PackageManager pm = context.getPackageManager();
        
        final ActivityManager am = (ActivityManager)
                context.getSystemService(Context.ACTIVITY_SERVICE);
        
        final List<ActivityManager.RecentTaskInfo> recentTasks =
                am.getRecentTasks(MAX_RECENT_TASKS, ActivityManager.RECENT_WITH_EXCLUDED);

        ActivityInfo homeInfo = 
            new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
                    .resolveActivityInfo(pm, 0);

        IconUtilities iconUtilities = new IconUtilities(getContext());

        // Performance note:  Our android performance guide says to prefer Iterator when
        // using a List class, but because we know that getRecentTasks() always returns
        // an ArrayList<>, we'll use a simple index instead.
        int index = 0;
        int numTasks = recentTasks.size();
        
        for (int i = 0; i < numTasks && (index < NUM_BUTTONS); ++i) {
        	
            final ActivityManager.RecentTaskInfo info = recentTasks.get(i);

            // for debug purposes only, disallow first result to create empty lists
            if (DBG_FORCE_EMPTY_LIST && (i == 0)) continue;

            Intent intent = new Intent(info.baseIntent);
            if (info.origActivity != null) {
                intent.setComponent(info.origActivity);
            }

            // Skip the current home activity.
            if (homeInfo != null) {
                if (homeInfo.packageName.equals(
                        intent.getComponent().getPackageName())
                        && homeInfo.name.equals(
                                intent.getComponent().getClassName())) {
                    continue;
                }
            }

            intent.setFlags((intent.getFlags()&~Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED)
                    | Intent.FLAG_ACTIVITY_NEW_TASK);
            
            final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
            
            if (resolveInfo != null) {
                final ActivityInfo activityInfo = resolveInfo.activityInfo;
                final String title = activityInfo.loadLabel(pm).toString();
                Drawable icon = activityInfo.loadIcon(pm);

                if (title != null && title.length() > 0 && icon != null) {
                    final TextView tv = mIcons[index];
                    tv.setText(title);
                    icon = iconUtilities.createIconDrawable(icon);
                    tv.setCompoundDrawables(null, icon, null, null);
                    tv.setTag(intent);
                    tv.setVisibility(View.VISIBLE);
                    tv.setPressed(false);
                    tv.clearFocus();
                    ++index;
                }
            }
        }

        // handle the case of "no icons to show"
        mNoAppsText.setVisibility((index == 0) ? View.VISIBLE : View.GONE);

        // hide the rest
        for (; index < NUM_BUTTONS; ++index) {
            mIcons[index].setVisibility(View.GONE);
        }
        
    }

    /**
     * This is the listener for the ACTION_CLOSE_SYSTEM_DIALOGS intent.  It's an indication that
     * we should close ourselves immediately, in order to allow a higher-priority UI to take over
     * (e.g. phone call received).
     */
    private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
                    dismiss();
            }
        }
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="cn.flyaudio.andriod"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />
    <!-- 获取任务权限 -->
	<uses-permission android:name="android.permission.GET_TASKS"/>
	<!-- 加权限限制Home键 -->  
	<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.MONKEY"/>
            </intent-filter>
        </activity>
        <service android:name=".HomeService"></service>
    </application>
</manifest>
 

 


    
[3] 多线程断点上传下载种
    来源: 互联网  发布时间: 2014-02-18
多线程断点上传下载类

public class MulThreadDownload {

/**
* @param args
*/
public static void main(String[] args) {
String path = "http://net.itcast.cn/QQWubiSetup.exe";
try {
new MulThreadDownload().download(path, 3);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 从路径中获取文件名称
* @param path 下载路径
* @return
*/
public static String getFilename(String path){
return path.substring(path.lastIndexOf('/')+1);
}
/**
* 下载文件
* @param path 下载路径
* @param threadsize 线程数
*/
public void download(String path, int threadsize) throws Exception{
URL url = new URL(/blog_article/path/index.html);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
int filelength = conn.getContentLength();//获取要下载的文件的长度
String filename = getFilename(path);//从路径中获取文件名称
File saveFile = new File(filename);
RandomAccessFile accessFile = new RandomAccessFile(saveFile, "rwd");
accessFile.setLength(filelength);//设置本地文件的长度和下载文件相同
accessFile.close();
//计算每条线程下载的数据长度
int block = filelength%threadsize==0? filelength/threadsize : filelength/threadsize+1;
for(int threadid=0 ; threadid < threadsize ; threadid++){
new DownloadThread(url, saveFile, block, threadid).start();
}
}

private final class DownloadThread extends Thread{
private URL url;
private File saveFile;
private int block;//每条线程下载的数据长度
private int threadid;//线程id

public DownloadThread(URL url, File saveFile, int block, int threadid) {
this.url = url;
this.saveFile = saveFile;
this.block = block;
this.threadid = threadid;
}

@Override
public void run() {
//计算开始位置公式:线程id*每条线程下载的数据长度= ?
    //计算结束位置公式:(线程id +1)*每条线程下载的数据长度-1 =?
int startposition = threadid * block;
int endposition = (threadid + 1 ) * block - 1;
try {
RandomAccessFile accessFile = new RandomAccessFile(saveFile, "rwd");
accessFile.seek(startposition);//设置从什么位置开始写入数据
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
conn.setRequestProperty("Range", "bytes="+ startposition+ "-"+ endposition);
InputStream inStream = conn.getInputStream();
byte[] buffer = new byte[1024];
int len = 0;
while( (len=inStream.read(buffer)) != -1 ){
accessFile.write(buffer, 0, len);
}
inStream.close();
accessFile.close();
System.out.println("线程id:"+ threadid+ "下载完成");
} catch (Exception e) {
e.printStackTrace();
}
}
}

}

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3