当前位置:  编程技术>移动开发
本页文章导读:
    ▪解决UIScrollView缴获touch事件的一个极其简单有效的办法        解决UIScrollView截获touch事件的一个极其简单有效的办法当UIScrollView将touch事件截获时,我们可以要写个UIScrollView的类别,把事件从UIScrollView传出去! @implementation UIScrollView (UITouch) - (void)touchesBeg.........
    ▪ 设计并兑现一个LogService,应用开发时可以打印log到视图(TextView)中显示        设计并实现一个LogService,应用开发时可以打印log到视图(TextView)中显示本文将设计并实现项目LogService,通过LogService,在开发应用时可以打印log到窗口中显示。 项目源码下载地址:http://down.........
    ▪ JQuery Mobile入门——抉择菜单       JQuery Mobile入门——选择菜单1、菜单由按钮和菜单两部分组成,当用户单击按钮选择其中一项后,菜单自动关闭,被单击按钮的值将自动更新为菜单中用户所选的值。将菜单的类型设置为自定.........

[1]解决UIScrollView缴获touch事件的一个极其简单有效的办法
    来源: 互联网  发布时间: 2014-02-18
解决UIScrollView截获touch事件的一个极其简单有效的办法
当UIScrollView将touch事件截获时,我们可以要写个UIScrollView的类别,把事件从UIScrollView传出去!
@implementation UIScrollView (UITouch)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //if(!self.dragging)
    {
        [[self nextResponder] touchesBegan:touches withEvent:event];
    }
    [super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    //if(!self.dragging)
    {
        [[self nextResponder] touchesMoved:touches withEvent:event];
    }
    [super touchesMoved:touches withEvent:event];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //if(!self.dragging)
    {
        [[self nextResponder] touchesEnded:touches withEvent:event];
    }
    [super touchesEnded:touches withEvent:event];
}
@end

然后重写nextResponder的touch方法就可以了。



    
[2] 设计并兑现一个LogService,应用开发时可以打印log到视图(TextView)中显示
    来源: 互联网  发布时间: 2014-02-18
设计并实现一个LogService,应用开发时可以打印log到视图(TextView)中显示

本文将设计并实现项目LogService,通过LogService,在开发应用时可以打印log到窗口中显示。

项目源码下载地址:http://download.csdn.net/detail/guggy/4998148

Log Watcher窗口截图:



LogService包括以下3个部分:

1. service 它负责接收客户应用的log信息,并把它发给activity显示。支持多个客户应用同时打log。在AndroidManifest.xml中声明为:

        <service
            android:name=".LogService"
            android:process=":remote" >
            <intent-filter>
                <!--
                     These are the interfaces supported by the service, which
                     you can bind to.
                -->
                <action android:name="cn.livelog.logservice.IRemoteService" />
                <action android:name="cn.livelog.logservice.ILogy" />
            </intent-filter>
        </service>

2. activity 它的布局包含一个TextView,用来显示log,在AndroidManifest.xml中声明为:

       <activity android:name=".LogService$Binding"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="Log Watcher" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

3. cn-livelog-logservice-api.jar,提供接口给客户应用,编译时使用,接口包括:

    Logy.open(Context context)   打开log服务,打开后就可以通过Logy.d打印。

    Logy.close()                           关闭log服务,如果不调用,应用退出时会自动关闭log服务。

    Logy.d(String text)                  打印log,text为需要打印的字符串。


Logy.java文件如下:

public class Logy {

    private static Context mContext = null;
    private static ILogy mLogyService = null;

    public static boolean open(Context context) {
        boolean success = context.bindService(new Intent(ILogy.class.getName()), mLogyConnection,
                Context.BIND_AUTO_CREATE);
        if (success) {
            mContext = context;
        }
        return success;
    }

    public static boolean close( ) {
        if (mContext != null) {
            mContext.unbindService(mLogyConnection);
            mContext = null;
            return true;
        }
        return false;
    }

    public static void d(String text) {
        if (mLogyService != null) {
            try {
                mLogyService.printf(text);
            } catch (RemoteException ex) {
                ;
            }
        }
    }

    private static ServiceConnection mLogyConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName className, IBinder service) {
            // Connecting to a secondary interface is the same as any
            // other interface.
            mLogyService = ILogy.Stub.asInterface(service);
        }

        public void onServiceDisconnected(ComponentName className) {
            mLogyService = null;
        }
    };

}



客户应用使用接口的示例:

public class HelloActivity extends Activity {
    Button mButton1, mButton2;
    EditText mEditText;
    private PowerManager mPowerManager;
    /**
     * Called with the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the layout for this activity. You can find it
        // in res/layout/hello_activity.xml
        setContentView(R.layout.hello_activity);

        Logy.open(this);  //打开log服务

        mButton1 = (Button)findViewById(R.id.button1);
        mButton1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mEditText.setText("good morning!");
                Logy.d("I am from www.livelog.cn\n");  //打印
            }
        });

        mButton2 = (Button)findViewById(R.id.button2);
        mButton2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                mEditText.setText("good evening!");
                Logy.d("I am from www.hahatao.cn\n");  //打印
            }
        });

        mEditText = (EditText)findViewById(R.id.text);
    }
}


LogService.java是该项目的核心文件,实现了LogService和Log显示界面。LogService和Activity分别运行在2个不同的进程中,Activity通过bindService来启动LogService,LogService从客户应用接收log后,通过binder回调显示到Activity的TextView中。

下面是源码:

public class LogService extends Service {
    /**
     * This is a list of callbacks that have been registered with the
     * service.  Note that this is package scoped (instead of private) so
     * that it can be accessed more efficiently from inner classes.
     */
    final RemoteCallbackList<IRemoteServiceCallback> mCallbacks
            = new RemoteCallbackList<IRemoteServiceCallback>();

    NotificationManager mNM;

    @Override
    public void onCreate() {
        mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // Display a notification about us starting.
        showNotification();
    }

    @Override
    public void onDestroy() {
        // Cancel the persistent notification.
        mNM.cancel(R.string.remote_service_started);

        // Tell the user we stopped.
        Toast.makeText(this, R.string.remote_service_stopped, Toast.LENGTH_SHORT).show();

        // Unregister all callbacks.
        mCallbacks.kill();

        // Remove the next pending message to increment the counter, stopping
        // the increment loop.
        mHandler.removeMessages(LOG_PRINT);
    }

    protected void sendMessage(int msgType, String obj) {
        Message msg = Message.obtain(mHandler, msgType);
        msg.obj = obj;
        msg.sendToTarget();
    }

// BEGIN_INCLUDE(exposing_a_service)
    @Override
    public IBinder onBind(Intent intent) {
        // Select the interface to return.  If your service only implements
        // a single interface, you can just return it here without checking
        // the Intent.
        if (IRemoteService.class.getName().equals(intent.getAction())) {
            return mBinder;
        }
        if (ILogy.class.getName().equals(intent.getAction())) {
            return mLogyBinder;
        }
        return null;
    }

    /**
     * The IRemoteInterface is defined through IDL
     */
    private final IRemoteService.Stub mBinder = new IRemoteService.Stub() {
        public void registerCallback(IRemoteServiceCallback cb) {
            if (cb != null) mCallbacks.register(cb);
        }
        public void unregisterCallback(IRemoteServiceCallback cb) {
            if (cb != null) mCallbacks.unregister(cb);
        }
    };

    /**
     * A Log interface to the service.
     */
    private final ILogy.Stub mLogyBinder = new ILogy.Stub() {
        public void printf(String text) {
            sendMessage(LOG_PRINT, text);
        }
    };
// END_INCLUDE(exposing_a_service)

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        Toast.makeText(this, "Task removed: " + rootIntent, Toast.LENGTH_LONG).show();
    }

    private static final int LOG_PRINT = 1;
    /**
     * Our Handler used to execute operations on the main thread.  This is used
     * to schedule increments of our value.
     */
    private final Handler mHandler = new Handler() {
        @Override public void handleMessage(Message msg) {
            switch (msg.what) {
                case LOG_PRINT: {
                    // Up it goes.
                    String text = (String)msg.obj;

                    // Broadcast to all clients the new value.
                    final int N = mCallbacks.beginBroadcast();
                    for (int i=0; i<N; i++) {
                        try {
                            mCallbacks.getBroadcastItem(i).printCallback(text);
                        } catch (RemoteException e) {
                            // The RemoteCallbackList will take care of removing
                            // the dead object for us.
                        }
                    }
                    mCallbacks.finishBroadcast();
                }
                break;

                default:
                    super.handleMessage(msg);
            }
        }
    };

    /**
     * Show a notification while this service is running.
     */
    private void showNotification() {
        // In this sample, we'll use the same text for the ticker and the expanded notification
        CharSequence text = getText(R.string.remote_service_started);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.stat_sample, text,
                System.currentTimeMillis());

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, Binding.class), 0);

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, getText(R.string.remote_service_label),
                       text, contentIntent);

        // Send the notification.
        // We use a string id because it is a unique number.  We use it later to cancel.
        mNM.notify(R.string.remote_service_started, notification);
    }

    // ----------------------------------

    /**
     * Example of binding and unbinding to the remote service.
     * This demonstrates the implementation of a service which the client will
     * bind to, interacting with it through an aidl interface.</p>
     *
     * <p>Note that this is implemented as an inner class only keep the sample
     * all together; typically this code would appear in some separate class.
     */
 // BEGIN_INCLUDE(calling_a_service)
    public static class Binding extends Activity {
        /** The primary interface we will be calling on the service. */
        IRemoteService mService = null;
        TextView mCallbackText;
        private boolean mIsBound;

        /**
         * Standard initialization of this activity.  Set up the UI, then wait
         * for the user to poke it before doing anything.
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.log_service_binding);

            mCallbackText = (TextView)findViewById(R.id.callback);

            bindService(new Intent(IRemoteService.class.getName()),
                    mConnection, Context.BIND_AUTO_CREATE);
            mIsBound = true;
        }

        /**
         * Class for interacting with the main interface of the service.
         */
        private ServiceConnection mConnection = new ServiceConnection() {
            public void onServiceConnected(ComponentName className,
                    IBinder service) {
                // This is called when the connection with the service has been
                // established, giving us the service object we can use to
                // interact with the service.  We are communicating with our
                // service through an IDL interface, so get a client-side
                // representation of that from the raw service object.
                mService = IRemoteService.Stub.asInterface(service);

                // We want to monitor the service for as long as we are
                // connected to it.
                try {
                    mService.registerCallback(mCallback);
                } catch (RemoteException e) {
                    // In this case the service has crashed before we could even
                    // do anything with it; we can count on soon being
                    // disconnected (and then reconnected if it can be restarted)
                    // so there is no need to do anything here.
                }

                // As part of the sample, tell the user what happened.
                Toast.makeText(Binding.this, R.string.remote_service_started,
                        Toast.LENGTH_SHORT).show();
            }

            public void onServiceDisconnected(ComponentName className) {
                // This is called when the connection with the service has been
                // unexpectedly disconnected -- that is, its process crashed.
                mService = null;

                // As part of the sample, tell the user what happened.
                Toast.makeText(Binding.this, R.string.remote_service_stopped,
                        Toast.LENGTH_SHORT).show();
            }
        };

        private OnClickListener mBindListener = new OnClickListener() {
            public void onClick(View v) {
                // Establish a couple connections with the service, binding
                // by interface names.  This allows other applications to be
                // installed that replace the remote service by implementing
                // the same interface.
                bindService(new Intent(IRemoteService.class.getName()),
                        mConnection, Context.BIND_AUTO_CREATE);
                mIsBound = true;
            }
        };

        private OnClickListener mUnbindListener = new OnClickListener() {
            public void onClick(View v) {
                if (mIsBound) {
                    // If we have received the service, and hence registered with
                    // it, then now is the time to unregister.
                    if (mService != null) {
                        try {
                            mService.unregisterCallback(mCallback);
                        } catch (RemoteException e) {
                            // There is nothing special we need to do if the service
                            // has crashed.
                        }
                    }

                    // Detach our existing connection.
                    unbindService(mConnection);

                    mIsBound = false;
                }
            }
        };

        // ----------------------------------
        // Code showing how to deal with callbacks.
        // ----------------------------------

        /**
         * This implementation is used to receive callbacks from the remote
         * service.
         */
        private IRemoteServiceCallback mCallback = new IRemoteServiceCallback.Stub() {
            public void printCallback(String text) {
                mHandler.sendMessage(mHandler.obtainMessage(LOG_PRINT, text));

            }
        };

        private static final int LOG_PRINT = 1;

        private Handler mHandler = new Handler() {
            @Override public void handleMessage(Message msg) {
                switch (msg.what) {
                    case LOG_PRINT:
                        String text = mCallbackText.getText().toString();
                        mCallbackText.setText(text + (String)msg.obj);
                        break;

                    default:
                        super.handleMessage(msg);
                }
            }

        };
    }
// END_INCLUDE(calling_a_service)

}






    
[3] JQuery Mobile入门——抉择菜单
    来源: 互联网  发布时间: 2014-02-18
JQuery Mobile入门——选择菜单

1、菜单由按钮和菜单两部分组成,当用户单击按钮选择其中一项后,菜单自动关闭,被单击按钮的值将自动更新为菜单中用户所选的值。将菜单的类型设置为自定义,只需在<select>元素中,将data-native-menu属性值设为false即可。

2、示例代码:

<!DOCTYPE HTML >
<HTML>
  <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"><p>头部栏</p></div>
 <div data-role="content">
   <fieldset data-role="controlgroup" data-type="horizontal">
 <select name="selY" id="selY">
   <option>年份</option>
<option value="2011">2011<option>
<option value="2012">2012</option>
 </select>
 <select name="selM" id="selM" data-native-menu="false">
   <option>月份</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
            <option value="12">12</option>
 </select>
</fieldset>
 </div>
 <div data-role="footer"><h4>@2013 3I Studio</h4></div>
</div>
 </BODY>

</HTML>

3、效果图预览:
点击年份:点击月份:





    
最新技术文章:
▪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