当前位置:  编程技术>移动开发
本页文章导读:
    ▪JQuery Mobile入门——多品种型的网格布局        JQuery Mobile入门——多种类型的网格布局1、JQuery Mobile 提供的CSS样式ui-grid可以实现内容的网格布局,该样式有4种预设的配置布局:ui-grid-a、ui-grid-b、ui-grid-c、ui-grid-d,分别对应为两列、三列.........
    ▪ Notification中Intent携带数据重复有关问题        Notification中Intent携带数据重复问题 Notification中多个Intent使用putExtra方法携带数据,在目的activity中通过getIntent方法取出传递数据时,有时候会发现取出来的数据都是第一次putExtra中放入的数据.........
    ▪ unity StreamingAssets途径       unity StreamingAssets路径  我们在读写例如XML和TXT文件的时候,在电脑上和手机上路径不一致,造成了很多麻烦,其实有个简单的方法,在项目工程中新建一个StreamingAssets文件夹,把你的XML和TXT.........

[1]JQuery Mobile入门——多品种型的网格布局
    来源: 互联网  发布时间: 2014-02-18
JQuery Mobile入门——多种类型的网格布局

1、JQuery Mobile 提供的CSS样式ui-grid可以实现内容的网格布局,该样式有4种预设的配置布局:ui-grid-a、ui-grid-b、ui-grid-c、ui-grid-d,分别对应为两列、三列、四列、五列的网格布局形式。使用网格布局时,整个宽度为100%,无任何padding,margin及背景颜色,因此不会影响到其他元素放入网格中的位置。

2、示例代码:

<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <meta name="viewport" content="width=device-width,initial-scale=1"/>
  <link href="/blog_article/Css/jquery.mobile-1.2.0.min.css" rel="Stylesheet" type="text/css"/>
  <script src="/blog_article/Js/jquery-1.8.3.min.js" type"text/javascript"></script>
  <script src="/blog_article/Js/jquery.mobile-1.2.0.min.js" type="text/javascript"></script>
 </HEAD>
 <BODY>
    <div data-role="page">
 <div data-role="header"><h1>头部栏标题</h1></div>
 <div >
   <div >
 <div >A</div>
</div>
<div >
 <div h60>B</div>
</div>
 </div>
 <div >
   <div >
 <div h60>A</div>
</div>
<div >
 <div h60>B</div>
</div>
<div >
 <div h60>C</div>
</div>
 </div>
</div>
 </BODY>
</HTML>


3、效果图预览:



    
[2] Notification中Intent携带数据重复有关问题
    来源: 互联网  发布时间: 2014-02-18
Notification中Intent携带数据重复问题

Notification中多个Intent使用putExtra方法携带数据,在目的activity中通过getIntent方法取出传递数据时,有时候会发现取出来的数据都是第一次putExtra中放入的数据。

下面看下代码,比较简单:

package com.example.notificationdemo;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class FirstActivity extends Activity {
	
	private Button mButton;
	
	private NotificationManager mNotificationManager;
	private Intent mIntent;
	private PendingIntent mPendingIntent;
	Notification mNotification;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first);	
		
		mNotification = new Notification();
		mIntent = new Intent(FirstActivity.this, MainActivity.class);
		mIntent.putExtra("hello", "first");
		Log.v("@@@@@@", "this is put in intent first....");
		mNotificationManager = 
				(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
		//主要在于PendingIntent的getActivity方法中的参数
		mPendingIntent = PendingIntent.getActivity(FirstActivity.this, 0, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
		//如果使用下面注释掉的代码,将会出现上面说讲到的问题,当然在SecondActivity中也必须做修改
		//mPendingIntent = PendingIntent.getActivity(FirstActivity.this, 0, mIntent, 0);
		mButton = (Button)findViewById(R.id.first_button);
		mButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				showNotification();
			}
		});
	}
	
	private void showNotification() {  
		
		mNotification.icon = R.drawable.message;
		mNotification.defaults = Notification.DEFAULT_SOUND; 
		mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
		mNotification.tickerText = "第一个";
		mNotification.setLatestEventInfo(FirstActivity.this, "第一个",
				"第一个", mPendingIntent);
		mNotificationManager.notify(0, mNotification);
	}
}

第二个Activity:

package com.example.notificationdemo;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SecondActivity extends Activity {
	
	private Button mButton;	
	private NotificationManager mNotificationManager2;
	private Intent mIntent;
	private PendingIntent mPendingIntent2;
	Notification mNotification2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.second);
		
		mNotification2 = new Notification();
		mIntent = new Intent(SecondActivity.this, MainActivity.class);
		mIntent.putExtra("hello", "second");
		Log.v("@@@@@@", "this is doing in second activity");
		mNotificationManager2 = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
		mPendingIntent2 = PendingIntent.getActivity(SecondActivity.this, 1, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
		//如果使用下面注释掉的代码,将会出现上面说讲到的问题,当然在FirstActivity中也必须做修改(把上面代码注释掉,使用下面行代码,就会重现)
		//mPendingIntent2 = PendingIntent.getActivity(SecondActivity.this, 0, mIntent, 0);
		
		mButton = (Button) findViewById(R.id.second_button);		
		mButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				showNotification();
			}
		});	
	}
	
	private void showNotification() {    			
		
		mNotification2.icon = R.drawable.message2;
		mNotification2.defaults = Notification.DEFAULT_SOUND; 
		mNotification2.flags |= Notification.FLAG_AUTO_CANCEL;
		mNotification2.tickerText = "第二个";
		
		Log.v("@@@@@@", "intent put second ...");
		mNotification2.setLatestEventInfo(SecondActivity.this, "第二个", "第二个", mPendingIntent2);
		Log.v("@@@@@@", "do shownotification in second activity");
		mNotificationManager2.notify(0, mNotification2);
		
	}	
}

在MainActivity中接受两个Activity中的Notification传过来的数据:

package com.example.notificationdemo;

import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

public class MainActivity extends TabActivity implements OnCheckedChangeListener{

	private TabHost mTabHost;
	private RadioGroup mRadioGroup;
	private RadioButton mFirstRadio, mSecondRadio;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        mTabHost = getTabHost();
		mTabHost.addTab(mTabHost.newTabSpec("first").setIndicator("First").setContent(new Intent(this, FirstActivity.class)));
		mTabHost.addTab(mTabHost.newTabSpec("second").setIndicator("Second").setContent(new Intent(this, SecondActivity.class)));
        
        mRadioGroup = (RadioGroup) findViewById(R.id.radiogroup);
		mRadioGroup.setOnCheckedChangeListener(this);
		mFirstRadio = (RadioButton)findViewById(R.id.first_radio);
		mSecondRadio = (RadioButton) findViewById(R.id.second_radio);
		
		Log.v("@@@@@@", "this is doing  in onCreate");
        ChangeChecked(true);
        String str = getIntent().getStringExtra("hello");
    	Log.v("@@@@@@", "the str is " + str);
    	if (str != null && str.equals("first")) {
    		ChangeChecked(true);
    		mTabHost.setCurrentTabByTag("first");
    	} else if (str != null && str.equals("second")) {
    		ChangeChecked(false);
    		mTabHost.setCurrentTabByTag("second");
    	}
        
    }
    
    @Override
    protected void onNewIntent(Intent intent) {    	
    	String str = intent.getStringExtra("hello");
    	if (str != null && str.equals("first")) {
    		ChangeChecked(true);
    		mTabHost.setCurrentTabByTag("first");
    	} else if (str != null && str.equals("second")) {
    		ChangeChecked(false);
    		mTabHost.setCurrentTabByTag("second");
    	}
    	super.onNewIntent(intent);
    	
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) {
		case R.id.first_radio:
			mTabHost.setCurrentTabByTag("first");
			ChangeChecked(true);
			break;
		case R.id.second_radio:
			mTabHost.setCurrentTabByTag("second");
			ChangeChecked(false);
			break;
		default :
			break;
		}
		
	}
	
	private void ChangeChecked(boolean bool) {
		if (bool) {
			mFirstRadio.setTextColor(Color.RED);
			mFirstRadio.setBackgroundResource(R.drawable.tab_front_bg);
			mSecondRadio.setTextColor(Color.BLACK);
			mSecondRadio.setBackgroundColor(Color.TRANSPARENT);
		} else {
			mSecondRadio.setTextColor(Color.RED);
			mSecondRadio.setBackgroundResource(R.drawable.tab_front_bg);
			mFirstRadio.setTextColor(Color.BLACK);
			mFirstRadio.setBackgroundColor(Color.TRANSPARENT);
		}
	}
}

问题主要出自:

mPendingIntent2 = PendingIntent.getActivity(SecondActivity.this, 1, mIntent, PendingIntent.FLAG_UPDATE_CURRENT);
		//如果使用下面注释掉的代码,将会出现上面说讲到的问题,当然在FirstActivity中也必须做修改(把上面代码注释掉,使用下面行代码,就会重现)
		//mPendingIntent2 = PendingIntent.getActivity(SecondActivity.this, 0, mIntent, 0);

看一下getActivity方法:

 PendingIntent android.app.PendingIntent.getActivity(Context context, int requestCode, Intent intent, int flags)


Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

Parameters:
context The Context in which this PendingIntent should start the activity.
requestCode Private request code for the sender (currently not used).
intent Intent of the activity to be launched.
flags May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens.
Returns:
Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.


参数requestCode用于区分Intent,如果flag为FLAG_UPDATE_CURRENT会即使更新intent中数据。

关于该方法的详细概述,敬请查看后面关于notification的源码解析,打算在周末的时候看一下notification源码,那个时候再详细分析下。



    
[3] unity StreamingAssets途径
    来源: 互联网  发布时间: 2014-02-18
unity StreamingAssets路径

  我们在读写例如XML和TXT文件的时候,在电脑上和手机上路径不一致,造成了很多麻烦,其实有个简单的方法,在项目工程中新建一个StreamingAssets文件夹,把你的XML和TXT文件放到这里。

using UnityEngine; 
using System.Collections; 
using System.Xml; 
using System.Xml.Serialization; 
using System.IO; 
using System.Text; 
 
public class Reward  
 { 
   public int taskNo;
   
   public Task[] task = new Task[15];
   public Attribute attribute; 
   public Reward () {} 
   public struct Task
   { 
	  [XmlAttribute("taskReward")] 
	  public string taskReward{ get; set;} 
	  public Id id1; 
	  public Id id2;
      public Id id3;
   }
   public struct Id
   {
	  [XmlAttribute("flag")] 
	  public bool flag{ get; set;} 
	  [XmlAttribute("name")] 
	  public string name{ get; set;}
	  [XmlText()]
	  public string description{get;set;}
		
   }  
}

public class AchievementManager: MonoBehaviour { 
   Reward reward ; 
   FileInfo fileInfo;
   string _data; 
	
   void Start () 
   {   
      reward = new Reward();
	  LoadXML();
   } 
   void LoadXML() 
   { 
	  if(Application.platform == RuntimePlatform.IPhonePlayer)
	  {
		 fileInfo = new FileInfo(Application.dataPath + "/Raw/" + "Achievement.xml"); 
		  StreamReader r = fileInfo.OpenText(); 
         _data = r.ReadToEnd(); 
         r.Close(); 
	  }
	  else if(Application.platform == RuntimePlatform.Android)
	  {
		 fileInfo = new FileInfo(Application.streamingAssetsPath+"/Achievement.xml");
	     StartCoroutine("LoadWWW");
	  }
	  else
	  {
		 fileInfo = new FileInfo(Application.dataPath + "/StreamingAssets/"+ "Achievement.xml"); 
		 StreamReader r = fileInfo.OpenText(); 
         _data = r.ReadToEnd(); 
         r.Close(); 
      }	  
	  if(_data.ToString() != "") 
      { 
         reward = (Reward)DeserializeObject(_data);              
      } 
   }
   void OnGUI()
   {
	   GUI.Label(new Rect(0,0,Screen.width,Screen.height),"data:"+_data);	 
	   if(Input.GetKey(KeyCode.Space))
		{
			Application.Quit(); 
		}
   }
	
	IEnumerator LoadWWW()
	{
		WWW www = new WWW(Application.streamingAssetsPath+"/Achievement.xml");
		yield return www;
		_data =www.text;
	}
   public void Save()
   {     
      _data = SerializeObject(reward);
	  StreamWriter writer; 
      fileInfo.Delete();    
	  writer = fileInfo.CreateText(); 
      writer.Write(_data);
      writer.Close(); 
   }
   string UTF8ByteArrayToString(byte[] characters) 
   {      
      UTF8Encoding encoding = new UTF8Encoding(); 
      string constructedString = encoding.GetString(characters); 
      return (constructedString); 
   } 
 
   byte[] StringToUTF8ByteArray(string pXmlString) 
   { 
      UTF8Encoding encoding = new UTF8Encoding(); 
      byte[] byteArray = encoding.GetBytes(pXmlString); 
      return byteArray; 
   } 
 
   // Here we serialize our Reward object of reward 
   string SerializeObject(object pObject) 
   {
	  string XmlizedString = null; 
      MemoryStream memoryStream = new MemoryStream(); 
      XmlSerializer xs = new XmlSerializer(typeof(Reward)); 
      XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); 
      xs.Serialize(xmlTextWriter, pObject); 
      memoryStream = (MemoryStream)xmlTextWriter.BaseStream; 
      XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray()); 
      return XmlizedString; 
   } 
 
   // Here we deserialize it back into its original form 
   object DeserializeObject(string pXmlizedString) 
   { 
      XmlSerializer xs = new XmlSerializer(typeof(Reward)); 
      MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString)); 
      XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8); 
      return xs.Deserialize(memoryStream); 
   } 
}


注:其实每个平台的路径都可以是Application.streamingAssetsPath+"/Achievement.xml"。但是android平台必须要用WWW加载,其他的平台貌似也可以的,自己试试哈,呵呵~~~

 

 

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
IT科技资讯 iis7站长之家
▪根据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