程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> 用C++完成一個鏈式棧的實例代碼

用C++完成一個鏈式棧的實例代碼

編輯:關於C++

用C++完成一個鏈式棧的實例代碼。本站提示廣大學習愛好者:(用C++完成一個鏈式棧的實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是用C++完成一個鏈式棧的實例代碼正文


推舉浏覽:Android中微信搶紅包插件道理解析及開辟思緒

搶紅包的道理都差不多,普通是用Android的幫助功效(AccessibilityService類)先監聽告訴欄事宜或窗口變更事宜來查找紅包症結字然後去模仿點擊或翻開紅包。

上面附上源碼,法式已完成主動搶紅包,鎖屏黑屏狀況主動解鎖亮屏,Android4.X測試經由過程。函數詳細功效請看具體正文。
注:在聊天界面收到紅包不會主動翻開,由於告訴欄沒有新聞提醒從而監聽不了,此時只需手動點一下便可。其他未知情形請自行用LogCat調試,源碼曾經有相干的調試信息。軟件僅供進修文娛。

<pre ><span ></span><pre >import java.util.Calendar; 
import java.util.List; 
import android.accessibilityservice.AccessibilityService; 
import android.annotation.SuppressLint; 
import android.app.KeyguardManager; 
import android.app.KeyguardManager.KeyguardLock; 
import android.app.Notification; 
import android.app.PendingIntent; 
import android.app.PendingIntent.CanceledException; 
import android.content.Context; 
import android.media.MediaPlayer; 
import android.os.PowerManager; 
import android.util.Log; 
import android.view.accessibility.AccessibilityEvent; 
import android.view.accessibility.AccessibilityNodeInfo; 
import android.widget.Toast; 
public class Demo extends AccessibilityService {
private boolean canGet = false;//可否點擊紅包
private boolean enableKeyguard = true;//默許有屏幕鎖
//窗口狀況
private static final int WINDOW_NONE = 0;
private static final int WINDOW_LUCKYMONEY_RECEIVEUI = 1;
private static final int WINDOW_LUCKYMONEY_DETAIL = 2;
private static final int WINDOW_LAUNCHER = 3;
private static final int WINDOW_OTHER = -1;
//以後窗口
private int mCurrentWindow = WINDOW_NONE;
//鎖屏、解鎖相干
private KeyguardManager km;
private KeyguardLock kl;
//叫醒屏幕相干
private PowerManager pm;
private PowerManager.WakeLock wl = null;
//播放提醒聲響
private MediaPlayer player;
public void playSound(Context context) {
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
//夜間不播放提醒音
if(hour > 7 && hour < 22) { 
player.start();
}
}
//叫醒屏幕息爭鎖
private void wakeAndUnlock(boolean unLock)
{
if(unLock)
{
//若為黑屏狀況則叫醒屏幕
if(!pm.isScreenOn()) {
//獲得電源治理器對象,ACQUIRE_CAUSES_WAKEUP這個參數能從黑屏叫醒屏幕
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "bright");
//點亮屏幕
wl.acquire();
Log.i("demo", "亮屏");
}
//若在鎖屏界面則解鎖直接跳過鎖屏
if(km.inKeyguardRestrictedInputMode()) {
//設置解鎖標記,以斷定搶完紅包可否鎖屏
enableKeyguard = false;
//解鎖
kl.disableKeyguard();
Log.i("demo", "解鎖");
}
}
else
{
//假如之前解過鎖則加鎖以恢回復復興樣
if(!enableKeyguard) {
//鎖屏
kl.reenableKeyguard();
Log.i("demo", "加鎖");
}
//若之前叫醒過屏幕則釋放之使屏幕不堅持常亮
if(wl != null) {
wl.release();
wl = null;
Log.i("demo", "關燈");
}
}
}
//經由過程文本查找節點
public AccessibilityNodeInfo findNodeInfosByText(AccessibilityNodeInfo nodeInfo, String text) {
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText(text);
if(list == null || list.isEmpty()) {
return null;
}
return list.get(0);
}
//模仿點擊事宜
public void performClick(AccessibilityNodeInfo nodeInfo) {
if(nodeInfo == null) {
return;
}
if(nodeInfo.isClickable()) {
nodeInfo.performAction(AccessibilityNodeInfo.ACTION_CLICK);
} else {
performClick(nodeInfo.getParent());
}
}
//模仿前往事宜
public void performBack(AccessibilityService service) {
if(service == null) {
return;
}
service.performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
}
//完成幫助功效
@Override 
public void onAccessibilityEvent(AccessibilityEvent event) { 
int eventType = event.getEventType();
Log.i("demo", Integer.toString(eventType));
switch (eventType) { 
//第一步:監聽告訴欄新聞 
case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED: 
List<CharSequence> texts = event.getText(); 
if (!texts.isEmpty()) { 
for (CharSequence text : texts) { 
String content = text.toString(); 
Log.i("demo", "text:"+content);
//收到紅包提示
if (content.contains("[微信紅包]")||content.contains("[QQ紅包]")) { 
//模仿翻開告訴欄新聞 
if (event.getParcelableData() != null && event.getParcelableData() instanceof Notification) {
//播放提醒音
playSound(this);
//若是微信紅包則解鎖並主動翻開,若是qq紅包則只提醒並跳轉到有紅包的聊天界面,暫未完成qq紅包主動支付功效
if(content.contains("[微信紅包]"))
wakeAndUnlock(true);
Log.i("demo", "canGet=true");
canGet = true;
try {
Notification notification = (Notification) event.getParcelableData(); 
PendingIntent pendingIntent = notification.contentIntent; 
pendingIntent.send();
} catch (CanceledException e) { 
e.printStackTrace(); 
}
}
break;
} 
} 
} 
break;
//第二步:監聽能否進入微信紅包新聞界面 
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
String className = event.getClassName().toString();
if (className.equals("com.tencent.mm.ui.LauncherUI")) { 
mCurrentWindow = WINDOW_LAUNCHER;
//開端搶紅包 
Log.i("demo", "預備搶紅包...");
getPacket();
} else if (className.equals("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI")) {
mCurrentWindow = WINDOW_LUCKYMONEY_RECEIVEUI;
//開端翻開紅包
Log.i("demo", "翻開紅包");
openPacket();
wakeAndUnlock(false);
} else if(className.equals("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI")) {
mCurrentWindow = WINDOW_LUCKYMONEY_DETAIL;
//前往以便利下次收紅包
Log.i("demo", "前往");
performBack(this);
} else {
mCurrentWindow = WINDOW_OTHER;
}
break;
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
if(mCurrentWindow != WINDOW_LAUNCHER) { //不在聊天界面或聊天列表,不處置
return;
}
if(canGet) {
getPacket();
}
break;
}
}
//找到紅包並點擊
@SuppressLint("NewApi") 
private void getPacket() { 
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow(); 
if (nodeInfo == null) { 
return; 
}
// 找到支付紅包的點擊事宜 
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("支付紅包");
if(list != null ) {
if(list.isEmpty()) {
Log.i("demp", "支付列表為空");
// 從新聞列表查找紅包
AccessibilityNodeInfo node = findNodeInfosByText(nodeInfo, "[微信紅包]");
if(node != null) {
canGet = true;
performClick(node);
}
}
else {
if(canGet) {
//最新的紅包領起
AccessibilityNodeInfo node = list.get(list.size() - 1);
performClick(node);
Log.i("demo", "canGet=false");
canGet = false;
}
}
}
}
//翻開紅包
@SuppressLint("NewApi") 
private void openPacket() { 
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if(nodeInfo == null) {
return;
}
Log.i("demo", "查找翻開按鈕...");
AccessibilityNodeInfo targetNode = null;
//假如紅包曾經被搶完則直接前往
targetNode = findNodeInfosByText(nodeInfo, "看看年夜家的手氣");
if(targetNode != null) {
performBack(this);
return;
}
//經由過程組件名查找開紅包按鈕,還可經由過程組件id直接查找但須要曉得id且id輕易隨版本更新而變更,舊版微信還可直接搜“開”字找到按鈕
if(targetNode == null) { 
Log.i("demo", "翻開按鈕中...");
for (int i = 0; i < nodeInfo.getChildCount(); i++) {
AccessibilityNodeInfo node = nodeInfo.getChild(i);
if("android.widget.Button".equals(node.getClassName())) {
targetNode = node;
break;
}
}
}
//若查找到翻開按鈕則模仿點擊
if(targetNode != null) {
final AccessibilityNodeInfo n = targetNode;
performClick(n);
} 
} 
@Override
public void onInterrupt() {
Toast.makeText(this, "搶紅包辦事被中止啦~", Toast.LENGTH_LONG).show();
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.i("demo", "開啟");
//獲得電源治理器對象
pm=(PowerManager)getSystemService(Context.POWER_SERVICE);
//獲得鍵盤鎖治理器對象
km= (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);
//初始化一個鍵盤鎖治理器對象
kl = km.newKeyguardLock("unLock");
//初始化音頻
player = MediaPlayer.create(this, R.raw.songtip_m);

Toast.makeText(this, "_已開啟搶紅包辦事_", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i("demo", "封閉");
wakeAndUnlock(false);
Toast.makeText(this, "_已封閉搶紅包辦事_", Toast.LENGTH_LONG).show();
}
}

AndroidManifest.xml中聲明相干辦事和權限

<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" /> 
<application 
android:allowBackup="true" 
android:icon="@drawable/ic_launcher" 
android:label="@string/app_name" 
android:theme="@style/AppTheme" > 
<pre name="code" class="html"><service 
android:name="com.example.test.Demo" android:enabled="true" android:exported="true" android:label="@string/app_name" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" > <intent-filter> <action android:name="android.accessibilityservice.AccessibilityService" /> </intent-filter> <meta-data android:name="android.accessibilityservice" android:resource="@layout/accessibility_config"/></service></application>

accessibility_config.xml辦事設置裝備擺設內容以下

<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" 
android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged|typeWindowContentChanged" 
android:accessibilityFeedbackType="feedbackGeneric" 
android:accessibilityFlags="flagDefault" 
android:canRetrieveWindowContent="true" 
android:description="@string/desc" 
android:notificationTimeout="100" 
android:packageNames= "com.tencent.mm,com.tencent.mobileqq" /> 

個中description為幫助功效的描寫內容,packageNames為監聽的法式包名,此處只監聽微信和QQ的accessibilityEventTypes

以上所述是針對Android幫助功效AccessibilityService與搶紅包幫助的相干常識,願望對年夜家有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved